const co = require('co');
const activityDao = require('../../model/act/activity');
const controllerBase = require('../../core/controllerBase');
const errEnum = require("../../common/enum");
const validator = require("validator");
const config = require('../../configuration.json');
var date = require("silly-datetime");
class Indexcontroller extends controllerBase {
    /*
     * 类构造函数
     * 设置类需要的数据实体操作实例
     */
    constructor(application) {
        ///将对应的数据库实体对象传递至基类
        super(application, new activityDao());
    }

    initializeRouter(instance) {

        // this.app.get('/getAllHxByHbId/:hbId', function (req, res) {
        //     co(instance.getAllHxByHbId(req, res))
        //         .then(result => instance.responseResult(req, res, result))
        //         .catch(result => instance.responseResult(res, res, result))
        // });

        // 保存第11步骤
        this.app.post('/save11', function (req, res) {
             co(instance.save11(req, res))
                 .then(result => instance.responseResult(req, res, result))
                 .catch(result => instance.responseResult(res, res, result))
        });

        // 审核意见
        this.app.post('/saveShyj', function (req, res) {
            co(instance.saveShyj(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        // 查询区域
        this.app.get('/getSSQByPId/:pid', function (req, res) {
            co(instance.getSSQByPId(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        // 插入公司记录
        this.app.post('/getInsertHbAndHx', function (req, res) {
            co(instance.getInsertHbAndHx(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        this.app.post('/getInsertHb', function (req, res) {
            co(instance.getInsertHb(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        this.app.post('/getInsertHx', function (req, res) {
            co(instance.getInsertHx(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        this.app.get('/getHxById/:id', function (req, res) {
            co(instance.getHxById(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        this.app.get('/getHxByPid/:pid', function (req, res) {
            co(instance.getHxByPid(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        // this.app.get('/getHxById/:id', function (req, res) {
        //     co(instance.getHxById(req, res))
        //         .then(result => instance.responseResult(req, res, result))
        //         .catch(result => instance.responseResult(res, res, result))
        // });

        // 返回
        this.app.post('/getHxPj', function (req, res) {
            co(instance.getHxPj(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        // 初次审查
        this.app.post('/updateHx', function (req, res) {
            co(instance.updateHx(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        // 确认提交
        this.app.post('/qrtj', function (req, res) {
            co(instance.qrtj(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });
        


        // 复查
        this.app.post('/reUpdateHx', function (req, res) {
            co(instance.reUpdateHx(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });
        
        //#登录
        this.app.post('/login', function (req, res) {
            co(instance.login(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        this.app.post('/getAll', function (req, res) {
            co(instance.getAll(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        //#获取首页数据
        this.app.get('/indexs', function (req, res) {
            co(instance.details(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });


        //获取楼盘详情
        this.app.get('/indexs/:id', function (req, res) {
            co(instance.getActivityDetal(req))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => {
                    console.log(result);
                    instance.responseResult(req, res, result);
                });
        });


       //#获取富文本
       this.app.get('/richText', function (req, res) {
            co(instance.richText(req, res))
               .then(result => instance.responseResult(req, res, result))
               .catch(result => instance.responseResult(res, res, result))
            });

        
       //#获取该公司所有图片
       this.app.get('/getAllPic/:pid', function (req, res) {
        co(instance.getAllPic(req, res))
           .then(result => instance.responseResult(req, res, result))
           .catch(result => instance.responseResult(res, res, result))
        });

       //#获取该公司本次检查的所有图片
       this.app.get('/getAllPicByhHxid/:hxid', function (req, res) {
        co(instance.getAllPicByhHxid(req, res))
           .then(result => instance.responseResult(req, res, result))
           .catch(result => instance.responseResult(res, res, result))
        });
        
        
            
        //获取详情
        this.app.get('/detailHb/:hxid', function (req, res) {
            co(instance.detailHb(req))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => {
                    console.log(result);
                    instance.responseResult(req, res, result);
                });
        });

        //获取公司详情
        this.app.get('/detailHbById/:id', function (req, res) {
            co(instance.detailHbById(req))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => {
                    console.log(result);
                    instance.responseResult(req, res, result);
                });
        });
        

        //#获取HB数据
        this.app.post('/listHB', function (req, res) {
            co(instance.listHB(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });


        //#获取App数据
        this.app.get('/listApp', function (req, res) {
            co(instance.listApp(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        //#获取Kfs数据
        this.app.get('/listKfs', function (req, res) {
            co(instance.listKfs(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        //条件查询楼盘信息
        this.app.get('/index/home_base/query', function (req, res) {
            co(instance.QueryHomeBase(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        //条件查询楼盘信息:用于首页条件查询
        this.app.get('/index/home_base/indexQuery', function (req, res) {
            co(instance.QueryHomeBase(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        //楼盘更多详情
        this.app.get('/index/home_base/info/:id', function (req, res) {
            co(instance.homeBaseInfo(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        //户型详情
        this.app.get('/index/home_base_hx/:id', function (req, res) {
            co(instance.homeBaseHxInfo(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });
        //修改楼盘经纬度
        this.app.put('/index/home_base/update', function (req, res) {
            co(instance.updateHomeBaseLonAndLat(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        //商业贷款计算器：按贷款总额计算
        this.app.get('/index/fdSydkZeCalculator', function (req, res) {
            co(instance.fdSydkZeCalculator(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        //商业贷款计算器：按面积、单价计算
        this.app.get('/index/fdSydkMjCalculator', function (req, res) {
            co(instance.fdSydkMjCalculator(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        //组合贷款计算器
        this.app.get('/index/fdZhdkCalculator', function (req, res) {
            co(instance.fdZhdkCalculator(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });


        //购房能力评估
        this.app.get('/index/getPurchaseAbilityEvaluation', function (req, res) {
            co(instance.getPurchaseAbilityEvaluation(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        //贷款利率
        this.app.get('/index/getLendingRate', function (req, res) {
            co(instance.getLendingRate(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        //房贷计算器的使用记录
        this.app.post('/index/addHomeCalculator', function (req, res) {
            co(instance.addHomeCalculator(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        //查询楼盘动态
        this.app.get('/index/home_base/querylpdt/:pid', function (req, res) {
            co(instance.querylpdt(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });


        //获取楼盘相册
        this.app.get('/index/home_base/album/:pid', function (req, res) {
            co(instance.getHomeBaseAlbum(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });



        //根据经纬度获取楼盘信息
        this.app.get('/indexs/home_base/latandlon', function (req, res) {
            co(instance.latandlon(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });


        //新增crm_user_yhq_qa表数据
        this.app.post('/addUserYhqQa', function (req, res) {
            co(instance.addUserYhqQa(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });


        //查询广州分区楼盘
        this.app.get('/querygzfqlp', function (req, res) {
            co(instance.querygzfqlp(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });


        //按名字返回楼盘
        this.app.get('/getQueryName', function (req, res) {
            co(instance.getQueryName(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });


        //楼盘对比
        this.app.get('/getHomeBaseContrast', function (req, res) {
            co(instance.getHomeBaseContrast(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        //猜你喜欢楼盘
        this.app.get('/getInterestHomeBase', function (req, res) {
            co(instance.getInterestHomeBase(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        //猜你喜欢楼盘MINi
        this.app.get('/getMiniInterestHomeBase', function (req, res) {
            co(instance.getMiniInterestHomeBase(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });


        //修改home_base视频
        this.app.get('/updatevideo', function (req, res) {
            co(instance.updatevideo(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });


        //帮我找房页面数据
        this.app.get('/index/getFindHomeBaseInfo', function (req, res) {
            co(instance.getFindHomeBaseInfo(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });


    }

    //获取楼盘详情
    * getActivityDetal(req) {
        let r = {};
        let id = req.params.id;
        let uid = req.query.uid;
        r.uid = uid
        //从配置类获取请求头前缀
        let httpHead = config.appsetting.picHead
        //从配置类获取楼盘图片类型
        let sourceLppicTypeList = config.sourceLppicTypeList
        //清空缓存从配置类获取楼盘图片类型
        for (let a = 0; a < sourceLppicTypeList.length; a++) {
            //前端用来判断
            sourceLppicTypeList[a].isActive = false
            sourceLppicTypeList[a].list = []
        }



        //获取楼盘图片
        let sqlImageList = `SELECT path,img,lppic_type FROM source_list a WHERE pid=${id} AND source_type=1	AND showit=1  AND del='0' ;`;
        let result_imageList = yield this._daoModel.query(sqlImageList);
        let arrImageList = result_imageList.rows
        for (let i = 0; i < arrImageList.length; i++) {
            if (arrImageList[i].path) {
                let a = arrImageList[i].path.substring(0, 4)
                //判断有没有http前缀
                if (a != 'http') {
                    arrImageList[i].path = httpHead + arrImageList[i].path
                }
            }
            if (arrImageList[i].img) {
                let a = arrImageList[i].img.substring(0, 4)
                //判断有没有http前缀
                if (a != 'http') {
                    arrImageList[i].img = httpHead + arrImageList[i].img
                }
            }
            for (let a = 0; a < sourceLppicTypeList.length; a++) {
                if (sourceLppicTypeList[a].id == arrImageList[i].lppic_type) {
                    sourceLppicTypeList[a].list.push(arrImageList[i])
                }
            }

        }
        //获取楼盘图片分类数据
        r.sourceLppicTypeList = sourceLppicTypeList
        // r.imageList = arrImageList
        //获取楼盘图片数量
        r.imageListLength = arrImageList.length

        // 获取楼盘基本信息
        let sql_home_base = `SELECT a.id,a.name,a.xszt,b.name jzlxname,a.address,a.sf,a.sq,a.qy,a.xsjg,a.cqnx,a.zxqk,a.kpsj,a.dtqk,a.lon,a.lat,a.city,a.vids,a.phone,a.smzh,a.pics,c.rich_text
        FROM home_base a
        LEFT JOIN home_jzlx b ON a.jzlx_id=b.id
        LEFT JOIN bas_richtext c ON a.lpgk=c.data_id
        WHERE a.id=${id} AND a.del='0'`;
        let result_home_base = yield this._daoModel.query(sql_home_base);
        let arrHomeBase = result_home_base.rows[0]
        if (arrHomeBase) {
            let pic = arrHomeBase.pics
            if (pic) {
                let a = pic.substring(0, 4)
                //判断有没有http前缀
                if (a != 'http') {
                    arrHomeBase.pics = httpHead + pic
                }
            }

            let video = arrHomeBase.vids
            // 获取楼盘视频信息
            let sql_video = `SELECT path,img,lppic_type FROM source_list a WHERE pid=${id} AND source_type=2  AND lppic_type=3  AND showit=1  AND del='0' ORDER BY id LIMIT 1`;
            let result_video = yield this._daoModel.query(sql_video);
            let arrVideo = result_video.rows[0]
            if (video) {
                let a = video.substring(0, 4)
                //判断有没有http前缀
                if (a != 'http') {
                    arrHomeBase.vids = httpHead + video
                }
                let arrVideo2 = {}
                arrVideo2.isActive = true
                arrVideo2.name = '视频'
                arrVideo2.path = arrHomeBase.vids
                arrVideo2.lppic_type = 3
                if (arrVideo) {
                    let img = arrVideo.img
                    if (img) {
                        let a = img.substring(0, 4)
                        arrVideo2.img = img
                        //判断有没有http前缀
                        if (a != 'http') {
                            arrVideo2.img = httpHead + img
                        }
                    } else {
                        arrVideo2.img = arrHomeBase.pics
                    }
                } else {
                    arrVideo2.img = arrHomeBase.pics
                }
                r.arrVideo = arrVideo2
            } else {
                if (arrVideo) {
                    let video = arrVideo.path
                    let sql_update = `UPDATE home_base SET vids='${video}' WHERE  id=${id}`;
                    let result_update = yield this._daoModel.query(sql_update);

                    //前端用来判断
                    arrVideo.isActive = true
                    arrVideo.name = '视频'

                    if (video) {
                        let a = video.substring(0, 4)
                        //判断有没有http前缀
                        if (a != 'http') {
                            arrVideo.path = httpHead + video
                        }
                    }
                    let img = arrVideo.img
                    if (img) {
                        let a = img.substring(0, 4)
                        //判断有没有http前缀
                        if (a != 'http') {
                            arrVideo.img = httpHead + img
                        }
                    } else {
                        arrVideo.img = arrHomeBase.pics
                    }
                }
                r.arrVideo = arrVideo
            }

            //收藏楼盘标识
            arrHomeBase.isSC = false
            if (uid) {
                //获取手机号
                let sqlUser_mobile = `SELECT user_id,user_mobile FROM crm_user WHERE user_id='${uid}'`
                let resultUser_mobile = yield this._daoModel.query(sqlUser_mobile);
                let user_mobileArr = resultUser_mobile.rows[0]
                let userMobile = user_mobileArr.user_mobile;
                let sqlFavorItem = ``;
                if (userMobile) {
                    sqlFavorItem = `SELECT COUNT(1) num FROM home_favor_item a WHERE a.pid=${id} AND a.uid IN (SELECT user_id FROM crm_user WHERE user_mobile=(SELECT user_mobile FROM crm_user WHERE user_id='${uid}'))`
                } else {
                    sqlFavorItem = `SELECT COUNT(1) num FROM home_favor_item a WHERE a.pid=${id} AND a.uid='${uid}'`
                }
                let resultFavorItem = yield this._daoModel.query(sqlFavorItem);
                let arrFavorItem = resultFavorItem.rows[0]
                if (arrFavorItem.num > 0) {
                    arrHomeBase.isSC = true
                }
            }

        } else {
            return {
                code: 1,
                successed: true,
                rows: r
            };
        }

        //查询楼盘动态
        let sql_home_dyanmic = `SELECT * FROM home_dynamic WHERE pid=${id}  AND del=0 ORDER BY time DESC`;
        let result_sql_home_dyanmic = yield this._daoModel.query(sql_home_dyanmic);
        let arrHomeDyanmic = result_sql_home_dyanmic.rows
        r.arrHomeDyanmic = arrHomeDyanmic


        let lpdtList = [] //楼盘动态
        let kpxxList = [] //开盘信息
        let jfxxList = [] //交房信息
        let zjxxList = [] //证件信息
        arrHomeDyanmic.forEach(element => {
            let hdtype = element.type
            if (hdtype == 0) {
                lpdtList.push(element)
            } else if (hdtype == 1) {
                zjxxList.push(element)
            } else if (hdtype == 2) {
                kpxxList.push(element)
            } else if (hdtype == 3) {
                jfxxList.push(element)
            }
        });
        r.lpdtList = lpdtList
        r.kpxxList = kpxxList
        r.jfxxList = jfxxList
        r.zjxxList = zjxxList


        // //查询最大建筑面积、参考总价和最小建筑面积、参考总价
        // let sql_maxAndMin = `select MAX(jzmj) maxJzmj,MIN(jzmj) minJzmj,MAX(ckzj) maxCkzj,MIN(ckzj) minCkzj from home_base_hx where pid=${id}  and xszt='0' and del=0`;
        // let result_maxAndMin = yield this._daoModel.query(sql_maxAndMin);
        // let arrMaxAndMin = result_maxAndMin.rows[0]

        // let strJzmj='待定'
        // let strCkzj='待定'
        // if (arrMaxAndMin) {
        //     //建筑面积 
        //     if (arrMaxAndMin.minJzmj > 0 && arrMaxAndMin.maxJzmj > 0) {
        //         strJzmj = parseInt(arrMaxAndMin.minJzmj) + '-' + parseInt(arrMaxAndMin.maxJzmj) + 'm²'
        //     }
        //     //参考总价
        //     if (arrMaxAndMin.minCkzj > 0 && arrMaxAndMin.maxCkzj > 0) {
        //         strCkzj = parseInt(arrMaxAndMin.minCkzj) + '-' + parseInt(arrMaxAndMin.maxCkzj) + '万'
        //     }
        // }
        // arrHomeBase.strJzmj=strJzmj
        // arrHomeBase.strCkzj=strCkzj

        //#待删除
        //查询最大建筑面积、参考总价和最小建筑面积、参考总价
        let sql_maxAndMin = `SELECT total_min minCkzj,total_max maxCkzj,mianji_min minJzmj,mianji_max maxJzmj FROM home_base WHERE id=${id}`;
        let result_maxAndMin = yield this._daoModel.query(sql_maxAndMin);
        let arrMaxAndMintt = result_maxAndMin.rows[0]
        if (arrMaxAndMintt.maxJzmj > 0 && arrMaxAndMintt.minJzmj > 0) {
            arrMaxAndMintt.maxJzmj = parseInt(arrMaxAndMintt.maxJzmj)
            arrMaxAndMintt.minJzmj = parseInt(arrMaxAndMintt.minJzmj)
        } else {
            arrMaxAndMintt.maxJzmj = '待定'
            arrMaxAndMintt.minJzmj = '待定'
        }
        if (arrMaxAndMintt.maxCkzj > 0 && arrMaxAndMintt.minCkzj > 0) {
            arrMaxAndMintt.maxCkzj = parseInt(arrMaxAndMintt.maxCkzj)
            arrMaxAndMintt.minCkzj = parseInt(arrMaxAndMintt.minCkzj)
        } else {
            arrMaxAndMintt.maxCkzj = '待定'
            arrMaxAndMintt.minCkzj = '待定'
        }
        let arrMaxAndMin = {
            "maxJzmj": arrMaxAndMintt.maxJzmj,
            "minJzmj": arrMaxAndMintt.minJzmj,
            "maxCkzj": arrMaxAndMintt.maxCkzj,
            "minCkzj": arrMaxAndMintt.minCkzj
        }

        arrHomeBase.jzmjAndCkzj = arrMaxAndMin


        let strJzmj = '待定'
        let strCkzj = '待定'
        if (arrMaxAndMin) {
            //建筑面积 
            if (arrMaxAndMin.minJzmj > 0 && arrMaxAndMin.maxJzmj > 0) {
                strJzmj = parseInt(arrMaxAndMin.minJzmj) + '-' + parseInt(arrMaxAndMin.maxJzmj) + 'm²'
            }
            //参考总价
            if (arrMaxAndMin.minCkzj > 0 && arrMaxAndMin.maxCkzj > 0) {
                strCkzj = parseInt(arrMaxAndMin.minCkzj) + '-' + parseInt(arrMaxAndMin.maxCkzj) + '万'
            }
        }
        arrHomeBase.strJzmj = strJzmj
        arrHomeBase.strCkzj = strCkzj
        //#待删除


        //获取户型信息
        let sql_homeLphx = `SELECT a.id,a.jjx,a.jzmj,a.ckzj,a.pics path,c.name,a.xszt,a.cx
        FROM home_base_hx a
        INNER JOIN home_lphx c ON c.id=a.lphx_id
        WHERE a.pid='${id}' AND a.del='0'`;
        let result_homeLphx = yield this._daoModel.query(sql_homeLphx);
        let arrHomeLphx = result_homeLphx.rows
        let hxfx = []
        for (let i = 0; i < arrHomeLphx.length; i++) {
            if (arrHomeLphx[i].path) {
                let a = arrHomeLphx[i].path.substring(0, 4)
                //判断有没有http前缀
                if (a != 'http') {
                    arrHomeLphx[i].path = httpHead + arrHomeLphx[i].path
                }
            }
            if (i < 4) {
                hxfx.push(arrHomeLphx[i])
            }

            // if(arrHomeLphx[i].ckzj==0){
            //     arrHomeLphx[i].ckzj='待定'
            // }else{
            //     arrHomeLphx[i].ckzj=arrHomeLphx[i].ckzj+'万/套'
            // }

            // if(arrHomeLphx[i].jzmj==0){
            //     arrHomeLphx[i].jzmj='待定'
            // }else{
            //     arrHomeLphx[i].jzmj=arrHomeLphx[i].jzmj+'㎡'
            // }

            //#待删除
            if (arrHomeLphx[i].ckzj == 0) {
                arrHomeLphx[i].ckzj = '待定'
            }

            if (arrHomeLphx[i].jzmj == 0) {
                arrHomeLphx[i].jzmj = '待定'
            }
            //#待删除


        }
        r.hxfxList = hxfx
        // r.arrHomeLphx = arrHomeLphx

        //查询户型分类及数量
        let sql_lphxName = `SELECT c.id,c.name,COUNT(c.name) num FROM home_base a INNER JOIN home_base_hx b ON a.id=b.pid  INNER JOIN home_lphx c ON b.lphx_id=c.id WHERE a.id=${id} AND b.del='0' GROUP BY c.id`;
        let result_lphxName = yield this._daoModel.query(sql_lphxName);
        let arrLphxName = result_lphxName.rows
        let all = {
            "id": 0,
            "name": "全部",
            "num": arrHomeLphx.length,
            "list": arrHomeLphx
        }
        let allLphxName = []
        allLphxName.push(all)
        //封装楼盘户型分类数据
        for (let i = 0; i < arrLphxName.length; i++) {
            let list = []
            let name1 = arrLphxName[i].name
            for (let z = 0; z < arrHomeLphx.length; z++) {
                let name2 = arrHomeLphx[z].name
                if (name1 == name2) {
                    list.push(arrHomeLphx[z])
                }
            }
            arrLphxName[i].list = list
            if (list.length > 0) {
                allLphxName.push(arrLphxName[i])
            }
        }
        r.arrLphxName = allLphxName

        //查询楼盘标签
        let sql_homeLabel1 = `SELECT a.label_id,a.label_name FROM bas_label a INNER JOIN home_label b ON a.label_id=b.label_id WHERE a.label_disabled=0 AND b.home_id=${id}`;
        let result_homeLabel1 = yield this._daoModel.query(sql_homeLabel1);
        let arrHomeLabel1 = result_homeLabel1.rows
        arrHomeBase.arrHomeLabel1 = arrHomeLabel1
        r.homeBaseInfo = arrHomeBase

        // 返回10条热销楼盘信息
        let city = 'fc0bef1d-2193-491c-9178-498882a3dada'
        if (arrHomeBase && arrHomeBase.city) {
            city = arrHomeBase.city
        }

        let sq = '广州市'
        if (arrHomeBase && arrHomeBase.sq) {
            sq = arrHomeBase.sq
        }
        let sql_district = `SELECT district_name FROM bas_district WHERE parent_id=(SELECT district_id FROM bas_district WHERE district_name='${sq}');`
        let result_district = yield this._daoModel.query(sql_district)
        let districtList = result_district.rows
        // for (let i = 0; i < districtList.length; i++) {
        //     let len=districtList[i].district_name.length;
        //     let a = districtList[i].district_name.substring(0, len-1)
        //     districtList[i].district_name=a;
        // }
        r.districtList = districtList


        r.city = city
        let sql_Rxhome_base = `SELECT a.id,a.pics,a.xszt,a.name,a.address,a.qy,a.xsjg,d.name jzlxname,f.name wylxname,a.lon,a.lat
        FROM home_base a
        INNER JOIN home_theme_item b ON a.id=b.pid
        INNER JOIN home_base_hx c ON c.pid=a.id
        INNER JOIN home_jzlx d ON d.id=a.jzlx_id
        INNER JOIN home_wylx f ON f.id=a.wylx_id
        WHERE b.theme_id=5  AND a.del=0 AND c.del=0 AND d.del=0 AND f.del=0 
        AND a.city='${city}' AND a.xszt='0'  GROUP BY a.id LIMIT 10`;
        let result_Rxhome_base = yield this._daoModel.query(sql_Rxhome_base);
        let arrRxHomeBase = result_Rxhome_base.rows
        let arrHomeBaseId = [] //接收楼盘id
        // uid='008c8b94-a1da-4f11-ba3a-937d70b57763'
        let arrFavorID = [] //接收收藏的楼盘id
        //收藏楼盘标识
        if (uid) {
            //获取手机号
            let sqlUser_mobile = `SELECT user_id,user_mobile FROM crm_user WHERE user_id='${uid}'`
            let resultUser_mobile = yield this._daoModel.query(sqlUser_mobile);
            let user_mobileArr = resultUser_mobile.rows[0]
            let userMobile = user_mobileArr.user_mobile;
            let sqlFavorItem = ``;
            if (userMobile) {
                sqlFavorItem = `SELECT a.pid FROM home_favor_item a WHERE a.uid IN (SELECT user_id FROM crm_user WHERE user_mobile=(SELECT user_mobile FROM crm_user WHERE user_id='${uid}'))`
            } else {
                sqlFavorItem = `SELECT a.pid FROM home_favor_item a WHERE a.uid='${uid}'`
            }
            let resultFavorItem = yield this._daoModel.query(sqlFavorItem);
            arrFavorID = resultFavorItem.rows
            r.arrFavorItem = arrFavorID
        }
        for (let i = 0; i < arrRxHomeBase.length; i++) {
            if (arrRxHomeBase[i].pics) {
                let a = arrRxHomeBase[i].pics.substring(0, 4)
                //判断有没有http前缀
                if (a != 'http') {
                    arrRxHomeBase[i].pics = httpHead + arrRxHomeBase[i].pics
                }
            }

            if (arrRxHomeBase[i].xsjg == 0) {
                arrRxHomeBase[i].xsjg = '暂无均价'
            } else {
                let a = arrRxHomeBase[i].xsjg
                arrRxHomeBase[i].xsjg = a + '元/m²'
            }

            //查询最大建筑面积、参考总价和最小建筑面积、参考总价
            let ttid = arrRxHomeBase[i].id
            let sql_maxAndMin = `SELECT total_min minCkzj,total_max maxCkzj,mianji_min minJzmj,mianji_max maxJzmj FROM home_base WHERE id=${ttid}`;
            let result_maxAndMin = yield this._daoModel.query(sql_maxAndMin);
            let arrMaxAndMin = result_maxAndMin.rows[0]

            let strJzmj = '待定'
            let strCkzj = '待定'
            if (arrMaxAndMin) {
                //建筑面积 
                if (arrMaxAndMin.minJzmj > 0 && arrMaxAndMin.maxJzmj > 0) {
                    strJzmj = parseInt(arrMaxAndMin.minJzmj) + '-' + parseInt(arrMaxAndMin.maxJzmj) + 'm²'
                }
                //参考总价
                if (arrMaxAndMin.minCkzj > 0 && arrMaxAndMin.maxCkzj > 0) {
                    strCkzj = parseInt(arrMaxAndMin.minCkzj) + '-' + parseInt(arrMaxAndMin.maxCkzj) + '万'
                }
            }
            arrRxHomeBase[i].strJzmj = strJzmj
            arrRxHomeBase[i].strCkzj = strCkzj

            //查询楼盘标签
            arrHomeBaseId.push(arrRxHomeBase[i].id)
            //标识用户是否收藏
            arrRxHomeBase[i].isSC = false
            for (let a = 0; a < arrFavorID.length; a++) {
                let rxid = arrRxHomeBase[i].id
                let fid = arrFavorID[a].pid
                if (rxid == fid) {
                    arrRxHomeBase[i].isSC = true
                }
            }
        }
        if (arrHomeBaseId.length > 0) {
            //查询楼盘标签
            let homeBaseIdArr = '('
            for (let i = 0; i < arrHomeBaseId.length; i++) {
                if (i == 0) {
                    homeBaseIdArr += arrHomeBaseId[i]
                } else {
                    homeBaseIdArr += ',' + arrHomeBaseId[i]
                }
            }
            homeBaseIdArr += ')'
            let sql_homeLabel = `SELECT a.label_id,a.label_name,b.home_id
            FROM bas_label a INNER JOIN home_label b ON a.label_id=b.label_id
            WHERE a.label_disabled=0 AND b.home_id IN ${homeBaseIdArr}`;
            let result_homeLabel = yield this._daoModel.query(sql_homeLabel);
            let arrHomeLabel = result_homeLabel.rows

            for (let i = 0; i < arrRxHomeBase.length; i++) {
                let hbId = arrRxHomeBase[i].id
                let homeLabelList = []
                let homeLabel = {}
                for (let a = 0; a < arrHomeLabel.length; a++) {
                    let home_id = arrHomeLabel[a].home_id
                    if (hbId == home_id) {
                        homeLabel = {
                            "label_id": arrHomeLabel[a].label_id,
                            "label_name": arrHomeLabel[a].label_name,
                            "home_id": arrHomeLabel[a].home_id
                        };
                        homeLabelList.push(homeLabel)
                    }
                }
                arrRxHomeBase[i].arrHomeLabel = homeLabelList
            }

            //楼盘信息添加楼盘居室
            let sql_homejjx = `SELECT DISTINCT a.id,b.jjx
            FROM home_base a INNER JOIN home_base_hx b ON b.pid=a.id
            WHERE b.xszt='0' AND b.del='0' AND a.id in ${homeBaseIdArr} `;
            let result_homejjx = yield this._daoModel.query(sql_homejjx);
            let arrHomeJS = result_homejjx.rows
            for (let i = 0; i < arrRxHomeBase.length; i++) {
                let hbId = arrRxHomeBase[i].id
                let homeJSList = []
                let homeJS = {}
                for (let a = 0; a < arrHomeJS.length; a++) {
                    let home_id = arrHomeJS[a].id
                    if (hbId == home_id) {
                        homeJS = {
                            "id": arrHomeJS[a].id,
                            "jjx": arrHomeJS[a].jjx
                        };
                        homeJSList.push(homeJS)
                    }
                }
                arrRxHomeBase[i].arrHomeJS = homeJSList
            }
        }
        r.HomeRxBaseList = arrRxHomeBase

        r.id = id
        //记录浏览记录
        if (id && uid) {
            //获取手机号
            let today = date.format(new Date(), 'YYYY-MM-DD HH:mm:ss'); //当前时间
            let sqlUser_mobile = `SELECT user_id,user_mobile FROM crm_user WHERE user_id='${uid}'`
            let resultUser_mobile = yield this._daoModel.query(sqlUser_mobile);
            let user_mobileArr = resultUser_mobile.rows[0]
            let userMobile = user_mobileArr.user_mobile;
            let sqlFavorItem = ``;
            if (userMobile) {
                sqlFavorItem = `SELECT id FROM home_see_item a WHERE a.pid=${id} AND a.uid IN (SELECT user_id FROM crm_user WHERE user_mobile=(SELECT user_mobile FROM crm_user WHERE user_id='${uid}'))`
            } else {
                sqlFavorItem = `SELECT id FROM home_see_item a WHERE a.pid=${id} AND a.uid='${uid}'`
            }
            let resultFavorItem = yield this._daoModel.query(sqlFavorItem);
            let arrFavorItem = resultFavorItem.rows
            r.arrFavorItem = arrFavorItem
            if (arrFavorItem.length == 0) {
                let sql = `INSERT INTO home_see_item(pid,uid,see_time) VALUES(${id},'${uid}','${today}')`
                let result = yield this._daoModel.query(sql);
            } else {
                for (let t = 0; t < arrFavorItem.length; t++) {
                    let id = arrFavorItem[t].id
                    let sql = `UPDATE home_see_item SET see_time='${today}' WHERE id='${id}'`
                    let result = yield this._daoModel.query(sql);
                }
            }
        }

        return {
            code: 1,
            successed: true,
            rows: r
        };
    }

    //#获取首页数据
    * details(req, res) {
        let r = {};
        let uid = req.query.uid; //当前用户id
        let city = req.query.city;
        city = city ? city : '广州市';
        //从配置类获取请求头前缀
        let httpHead = config.appsetting.picHead

        // uid='58131f81-02e3-4538-95cc-c6f2dab3cd22'
        // 轮播图数据
        let sql_portal_slider_image = `select a.image_id,a.slider_id,a.image_topic,a.image_subtitle,a.image_platform,a.image_index,a.image_url,a.image_href,a.image_json,a.image_start,a.image_end,a.image_disabled,a.ext_field1,a.ext_field2
        from portal_slider_image a
           INNER JOIN portal_slider b on b.slider_id=a.slider_id
         where b.slider_key='pc'
         and a.image_disabled=0 and b.rec_isdeleted=0`;
        let result_portal_slider_image = yield this._daoModel.query(sql_portal_slider_image);
        let arrPortalSliderImage = result_portal_slider_image.rows
        for (let i = 0; i < arrPortalSliderImage.length; i++) {
            if (arrPortalSliderImage[i].image_url) {
                let a = arrPortalSliderImage[i].image_url.substring(0, 4)
                //判断有没有http前缀
                if (a != 'http') {
                    arrPortalSliderImage[i].image_url = httpHead + arrPortalSliderImage[i].image_url
                }
            }
        }
        r.portalSliderImageList = arrPortalSliderImage

        // 返回App数据
        let sql_home_theme = "select * from home_app a where del=0";
        let result_home_theme = yield this._daoModel.query(sql_home_theme);
        let arrHomeTheme = result_home_theme.rows
        for (let i = 0; i < arrHomeTheme.length; i++) {
            if (arrHomeTheme[i].pic) {
                let a = arrHomeTheme[i].pic.substring(0, 4)
                //判断有没有http前缀
                if (a != 'http') {
                    arrHomeTheme[i].pic = httpHead + arrHomeTheme[i].pic
                }
            }
        }
        r.HomeThemeList = arrHomeTheme

        //主题楼盘
        //热销
        let sql_rx_home_base = `select a.id,a.pics,a.link,a.address,a.name
        from home_base a
        INNER JOIN home_theme_item b on a.id=b.pid
        where b.theme_id=5
 LIMIT 3`;
        let result_rx_home_base = yield this._daoModel.query(sql_rx_home_base);
        let arrRxHomeBase = result_rx_home_base.rows
        for (let i = 0; i < arrRxHomeBase.length; i++) {
            if (arrRxHomeBase[i].pics) {
                let a = arrRxHomeBase[i].pics.substring(0, 4)
                //判断有没有http前缀
                if (a != 'http') {
                    arrRxHomeBase[i].pics = httpHead + arrRxHomeBase[i].pics
                }
            }

            if (arrRxHomeBase[i].address) {
                let a = arrRxHomeBase[i].address.substring(0, 4)
                //判断有没有http前缀
                if (a != 'http') {
                    arrRxHomeBase[i].address = httpHead + arrRxHomeBase[i].address
                }
            }
        }
        r.RxHomeBaseList = arrRxHomeBase
        //人气楼盘
        let sql_rq_home_base = `select a.id,a.pics,a.link,a.address,a.name
        from home_base a
        INNER JOIN home_theme_item b on a.id=b.pid
        where b.theme_id=4
 LIMIT 4`;
        let result_rq_home_base = yield this._daoModel.query(sql_rq_home_base);
        let arrRqHomeBase = result_rq_home_base.rows
        for (let i = 0; i < arrRqHomeBase.length; i++) {
            if (arrRqHomeBase[i].pics) {
                let a = arrRqHomeBase[i].pics.substring(0, 4)
                //判断有没有http前缀
                if (a != 'http') {
                    arrRqHomeBase[i].pics = httpHead + arrRqHomeBase[i].pics
                }
            }

            if (arrRqHomeBase[i].address) {
                let a = arrRqHomeBase[i].address.substring(0, 4)
                //判断有没有http前缀
                if (a != 'http') {
                    arrRqHomeBase[i].address = httpHead + arrRqHomeBase[i].address
                }
            }

        }
        r.RqHomeBaseList = arrRqHomeBase
        //特价
        let sql_tj_home_base = `select a.id,a.pics,a.link,a.address,a.name
        from home_base a
        INNER JOIN home_theme_item b on a.id=b.pid
 
        where b.theme_id=3
 LIMIT 3`;
        let result_tj_home_base = yield this._daoModel.query(sql_tj_home_base);
        let arrTjHomeBase = result_tj_home_base.rows
        for (let i = 0; i < arrTjHomeBase.length; i++) {
            if (arrTjHomeBase[i].pics) {
                let a = arrTjHomeBase[i].pics.substring(0, 4)
                //判断有没有http前缀
                if (a != 'http') {
                    arrTjHomeBase[i].pics = httpHead + arrTjHomeBase[i].pics
                }
            }

            if (arrTjHomeBase[i].address) {
                let a = arrTjHomeBase[i].address.substring(0, 4)
                //判断有没有http前缀
                if (a != 'http') {
                    arrTjHomeBase[i].address = httpHead + arrTjHomeBase[i].address
                }
            }

        }
        r.TjHomeBaseList = arrTjHomeBase
        return {
            code: 1,
            successed: true,
            rows: r
        };

    }

    //楼盘更多详情
    * homeBaseInfo(req, res) {
        let id = req.params.id; //楼盘ID
        //从配置类获取请求头前缀
        let httpHead = config.appsetting.picHead
        let r = {};
        let sql = `select a.id,a.xsjg,c.name wylxName,b.name jzlxName,a.zxqk,a.cqnx,d.name kfsName,a.address,a.xszt,a.kpsj,a.jfsj,a.phone,a.pics,a.zdmj,a.jzmj,a.rjl,a.lhl,a.cwqk,a.wygs,a.wyf,a.smzh,a.xmts,a.sldz,a.lpgk,a.ldzs,a.zhs,a.lczk,a.fzrq
        from home_base a
        LEFT JOIN home_jzlx b on a.jzlx_id=b.id
        LEFT JOIN home_wylx c on a.wylx_id=c.id
        LEFT JOIN home_kfs d on a.kfs_id=d.id
        where a.id=${id}`
        let result = yield this._daoModel.query(sql)
        let hbInfo = result.rows[0]
        if (hbInfo.pics) {
            let a = hbInfo.pics.substring(0, 4)
            //判断有没有http前缀
            if (a != 'http') {
                hbInfo.pics = httpHead + hbInfo.pics
            }
            if (hbInfo.xsjg == 0) {
                hbInfo.xsjg = '暂无均价'
            } else {
                let a = hbInfo.xsjg
                hbInfo.xsjg = a + '元/m²'
            }
        }
        r.homeBaseInfo = hbInfo

        //主力户型
        let sql_zlhx = `select  distinct  jjx,lphx_id,b.name lphxName from home_base_hx a INNER JOIN home_lphx b on b.id=a.lphx_id where a.pid=${id} and a.sort=1  and a.del=0 and b.del=0`
        let zlhx_result = yield this._daoModel.query(sql_zlhx)
        let zlhxList = zlhx_result.rows
        r.zlhxList = zlhxList
       

        // 返回1条置业管家数据
        let arrCrmMembershipType = []
        let sql_crm_membership_type = "select member_id,member_name,ext_field1,ext_field2,ext_field3,share_title,share_image,button_text,member_poster,member_desc from crm_membership_type where member_level=2  and rec_isdeleted=0  LIMIT 1";
        let result_crm_membership_type = yield this._daoModel.query(sql_crm_membership_type)
        result_crm_membership_type.rows.map((item, index) => {

            if (item) {
                let share_image = item.share_image
                if (share_image) {
                    let a = share_image.substring(0, 4)
                    //判断有没有http前缀
                    if (a != 'http') {
                        item.share_image = httpHead + share_image

                    }
                }
                let member_poster = item.member_poster
                if (member_poster) {
                    let a = member_poster.substring(0, 4)
                    //判断有没有http前缀
                    if (a != 'http') {
                        item.member_poster = httpHead + member_poster
                    }
                }
                arrCrmMembershipType.push(item)
            }

        })
        r.arrCrmMembershipType = arrCrmMembershipType

        //热销
        let sql_rx_home_base = `select a.id,a.pics,a.name,a.address,a.qy,a.xsjg,a.lon,a.lat
        from home_base a
        INNER JOIN home_theme_item b on a.id=b.pid
        INNER JOIN home_base_hx c on c.pid=a.id
        where b.theme_id=5
         and a.city=(select district_id from bas_district where district_name like '广州%' limit 1)
         and a.xszt='0'  and a.del=0    GROUP BY a.id LIMIT 5`;
        let result_rx_home_base = yield this._daoModel.query(sql_rx_home_base);
        let arrRxHomeBase = result_rx_home_base.rows
        for (let i = 0; i < arrRxHomeBase.length; i++) {
            if (arrRxHomeBase[i].pics) {
                let a = arrRxHomeBase[i].pics.substring(0, 4)
                //判断有没有http前缀
                if (a != 'http') {
                    arrRxHomeBase[i].pics = httpHead + arrRxHomeBase[i].pics
                }
            }
            if (arrRxHomeBase[i].xsjg == 0) {
                arrRxHomeBase[i].xsjg = '暂无均价'
            } else {
                let a = arrRxHomeBase[i].xsjg
                arrRxHomeBase[i].xsjg = a + '元/m²'
            }



            // //查询最大建筑面积、参考总价和最小建筑面积、参考总价
            // let ttid = arrRxHomeBase[i].id
            // let sql_maxAndMin = `select MAX(jzmj) maxJzmj,MIN(jzmj) minJzmj,MAX(ckzj) maxCkzj,MIN(ckzj) minCkzj from home_base_hx where pid=${ttid}  and xszt='0' and del=0`;
            // let result_maxAndMin = yield this._daoModel.query(sql_maxAndMin);
            // let arrMaxAndMin = result_maxAndMin.rows[0]

            // let strJzmj = '待定'
            // let strCkzj = '待定'
            // if (arrMaxAndMin) {
            //     //建筑面积 
            //     if (arrMaxAndMin.minJzmj > 0 && arrMaxAndMin.maxJzmj > 0) {
            //         strJzmj = parseInt(arrMaxAndMin.minJzmj) + '-' + parseInt(arrMaxAndMin.maxJzmj) + 'm²'
            //     }
            //     //参考总价
            //     if (arrMaxAndMin.minCkzj > 0 && arrMaxAndMin.maxCkzj > 0) {
            //         strCkzj = parseInt(arrMaxAndMin.minCkzj) + '-' + parseInt(arrMaxAndMin.maxCkzj) + '万'
            //     }
            // }
            // arrRxHomeBase[i].strJzmj = strJzmj
            // arrRxHomeBase[i].strCkzj = strCkzj


            //#待删除
            //查询最大建筑面积、参考总价和最小建筑面积、参考总价
            let ttid = arrRxHomeBase[i].id
            let sql_maxAndMin = `SELECT total_min minCkzj,total_max maxCkzj,mianji_min minJzmj,mianji_max maxJzmj FROM home_base where id=${ttid}`;
            let result_maxAndMin = yield this._daoModel.query(sql_maxAndMin);
            let arrMaxAndMintt = result_maxAndMin.rows[0]
            if (arrMaxAndMintt.maxJzmj > 0 && arrMaxAndMintt.minJzmj > 0) {
                arrMaxAndMintt.maxJzmj = parseInt(arrMaxAndMintt.maxJzmj)
                arrMaxAndMintt.minJzmj = parseInt(arrMaxAndMintt.minJzmj)
            } else {
                arrMaxAndMintt.maxJzmj = '待定'
                arrMaxAndMintt.minJzmj = '待定'
            }
            if (arrMaxAndMintt.maxCkzj > 0 && arrMaxAndMintt.minCkzj > 0) {
                arrMaxAndMintt.maxCkzj = parseInt(arrMaxAndMintt.maxCkzj)
                arrMaxAndMintt.minCkzj = parseInt(arrMaxAndMintt.minCkzj)
            } else {
                arrMaxAndMintt.maxCkzj = '待定'
                arrMaxAndMintt.minCkzj = '待定'
            }
            let arrMaxAndMin = {
                "maxJzmj": arrMaxAndMintt.maxJzmj,
                "minJzmj": arrMaxAndMintt.minJzmj,
                "maxCkzj": arrMaxAndMintt.maxCkzj,
                "minCkzj": arrMaxAndMintt.minCkzj
            }


            arrRxHomeBase[i].jzmjAndCkzj = arrMaxAndMin



            //建筑面积
            let strJzmj = parseInt(arrMaxAndMintt.minJzmj) + '-' + parseInt(arrMaxAndMintt.maxJzmj) + 'm²'
            if (arrMaxAndMintt.minJzmj == '待定' || arrMaxAndMintt.maxJzmj == '待定' || arrMaxAndMintt.minJzmj == 0 || arrMaxAndMintt.maxJzmj == 0 || arrMaxAndMintt.minJzmj == "null" || arrMaxAndMintt.maxJzmj == "null") {
                strJzmj = '待定'
            }
            arrRxHomeBase[i].strJzmj = strJzmj
            //参考总价
            let strCkzj = parseInt(arrMaxAndMintt.minCkzj) + '-' + parseInt(arrMaxAndMintt.maxCkzj) + '万'
            if (arrMaxAndMintt.minCkzj == '待定' || arrMaxAndMintt.maxCkzj == '待定' || arrMaxAndMintt.minCkzj == 0 || arrMaxAndMintt.maxCkzj == 0 || arrMaxAndMintt.minCkzj == "null" || arrMaxAndMintt.maxCkzj == "null") {
                strCkzj = '待定'
            }
            arrRxHomeBase[i].strCkzj = strCkzj
            //#待删除

        }
        r.RxHomeBaseList = arrRxHomeBase

        return {
            code: 1,
            successed: true,
            rows: r
        };
    }

    //户型详情
    * homeBaseHxInfo(req, res) {
        let id = req.params.id; //户型ID
        //从配置类获取请求头前缀
        let httpHead = config.appsetting.picHead
        let r = {};
        let sql = `SELECT a.id,a.pid,a.jjx,a.xszt,a.tags,a.ckzj,a.jzmj,a.cx,b.zxqk,c.name,b.cqnx,a.pics as path
        FROM home_base_hx a
     LEFT JOIN home_base b ON b.id=a.pid
     LEFT JOIN home_jzlx c ON b.jzlx_id=c.id
     WHERE a.id=${id} AND a.del=0 AND b.del=0 AND c.del=0`
        let result = yield this._daoModel.query(sql)
        let hxInfo = result.rows[0]
        if (hxInfo.path) {
            let a = hxInfo.path.substring(0, 4)
            //判断有没有http前缀
            if (a != 'http') {
                hxInfo.path = httpHead + hxInfo.path
            }
        }

        if (hxInfo.ckzj != 0 && hxInfo.jzmj != 0) {
            let ckjj = parseInt(hxInfo.ckzj * 10000 / hxInfo.jzmj)
            hxInfo.ckjj = ckjj + '元/m²'
        } else {
            hxInfo.ckjj = '待定'
        }

        // if(hxInfo.ckzj==0){
        //     hxInfo.ckzj='待定'
        // }else{
        //     hxInfo.ckzj=hxInfo.ckzj+'万/套'
        // }

        // if(hxInfo.jzmj==0){
        //     hxInfo.jzmj='待定'
        // }else{
        //     hxInfo.jzmj=hxInfo.jzmj+'㎡'
        // }



        //#待删除
        if (hxInfo.ckzj == 0) {
            hxInfo.ckzj = '待定'
        }

        if (hxInfo.jzmj == 0) {
            hxInfo.jzmj = '待定'
        }
        //#待删除


        let labelList = []
        if (hxInfo.tags) {
            let arr = hxInfo.tags
            let arrList = arr.trim().replace(/\n/g, ' ').replace(/\t/g, ' ').trim().split(" ")
            for (let i = 0; i < arrList.length; i++) {
                if (arrList[i] != " " && arrList[i] != "") {
                    labelList.push(arrList[i])
                }
            }
        }
        hxInfo.labelList = labelList

        r.homeBaseHxInfo = hxInfo

        //样板间图片
        let sql_ybj = `SELECT a.path FROM source_list a WHERE a.pid=${hxInfo.pid} AND a.lppic_type=9 AND a.source_type=1 AND a.showit=1 AND a.del='0' ;`
        let ybjImage_result = yield this._daoModel.query(sql_ybj)
        let ybjImageList = ybjImage_result.rows
        for (let i = 0; i < ybjImageList.length; i++) {
            if (ybjImageList[i].path) {
                let a = ybjImageList[i].path.substring(0, 4)
                //判断有没有http前缀
                if (a != 'http') {
                    ybjImageList[i].path = httpHead + ybjImageList[i].path
                }
            }
        }
        r.ybjImageList = ybjImageList

        //获取本楼盘其他户型信息
        let sql_homeLphx = `SELECT a.id,a.jjx,a.jzmj,a.ckzj,a.pics path,c.name,a.xszt
        FROM home_base_hx a
     INNER JOIN home_lphx c ON c.id=a.lphx_id
     WHERE a.pid=${hxInfo.pid} AND a.id<>${id} AND  c.del=0 AND a.del='0'`;
        let result_homeLphx = yield this._daoModel.query(sql_homeLphx);
        let arrHomeLphx = result_homeLphx.rows
        for (let i = 0; i < arrHomeLphx.length; i++) {
            if (arrHomeLphx[i].path) {
                let a = arrHomeLphx[i].path.substring(0, 4)
                //判断有没有http前缀
                if (a != 'http') {
                    arrHomeLphx[i].path = httpHead + arrHomeLphx[i].path
                }
            }


            // if(arrHomeLphx[i].ckzj==0){
            //     arrHomeLphx[i].ckzj='待定'
            // }else{
            //     arrHomeLphx[i].ckzj=arrHomeLphx[i].ckzj+'万/套'
            // }

            // if(arrHomeLphx[i].jzmj==0){
            //     arrHomeLphx[i].jzmj='待定'
            // }else{
            //     arrHomeLphx[i].jzmj=arrHomeLphx[i].jzmj+'㎡'
            // }


            //#待删除
            if (arrHomeLphx[i].ckzj == 0) {
                arrHomeLphx[i].ckzj = '待定'
            }

            if (arrHomeLphx[i].jzmj == 0) {
                arrHomeLphx[i].jzmj = '待定'
            }
            //#待删除

        }
        r.arrHomeLphx = arrHomeLphx
        return {
            code: 1,
            successed: true,
            rows: r
        };
    }

    //条件查询楼盘信息
    * QueryHomeBase(req, res) {
        let r = {};
        //从配置类获取请求头前缀
        let httpHead = config.appsetting.picHead
        //接收查询条件
        let uid = req.query.uid; //当前用户id
        let homeBaseName = req.query.name; //模糊查询名字
        let theme_id = req.query.theme_id; //专题ID
        let page = req.query.page; //分页条件：当前页
        let num = req.query.num; //分页条件：每页显示多少条
        let sq = req.query.sq; //市区
        let qy = req.query.qy; //区域	 
        let minZj = req.query.minZj; //最小总价
        let maxZj = req.query.maxZj; //最大总价	
        let minDj = req.query.minDj; //最小单价
        let maxDj = req.query.maxDj; //最大单价	
        let minMj = req.query.minMj; //最小面积
        let maxMj = req.query.maxMj; //最大面积
        let js = req.query.js; //居室		
        let lx = req.query.lx; //类型		
        let smqk = req.query.smqk; //售卖情况		
        let ts = req.query.ts; //特色		
        let kfs = req.query.kfs; //开发商	
        let labelId = req.query.label_id; //标签id
        let city = req.query.city; //定位
        let orderBy = req.query.orderBy; //根据单价排序
        let jjxSql = ``
        if (js && js != "0") {
            jjxSql = `LEFT JOIN home_base_hx d ON d.pid=a.id 
            LEFT JOIN home_lphx e ON e.id=d.lphx_id`
        }

        r.test = {
            "sq": sq,
            "qy": qy,
            "js": js,
            "minZj": minZj,
            "maxZj": maxZj,
            "city": city,
            "kfs": kfs,
            "minZj": minZj
        }
        // 返回楼盘信息
        let sql_home_base = `SELECT  SQL_CALC_FOUND_ROWS a.id,a.pics,a.name,a.address,a.sq,a.qy,a.xsjg,a.xszt,a.lon,a.lat,f.szqf,f.name wylxname,c.name jzlxname,a.total_min minCkzj,a.total_max maxCkzj,a.mianji_min minJzmj,a.mianji_max maxJzmj
        FROM home_base a
        LEFT JOIN home_theme_item b ON b.pid=a.id
        LEFT JOIN home_jzlx c ON c.id=a.jzlx_id
        ${jjxSql}
        LEFT JOIN home_wylx f ON f.id=a.wylx_id
        LEFT JOIN home_label g ON g.home_id=a.id`;
        let where = ` WHERE a.del=0 AND  c.del=0   AND f.del=0 `;
        let or = ``;
        //按名称模糊查询
        if (homeBaseName) {
            where += ` AND a.name LIKE '%${homeBaseName}%' `
        }

        if (!homeBaseName) {
            //选择区域
            if (sq && sq != "") {
                if (qy && qy != "") {
                    where += ` AND a.sq LIKE '${sq}%'   AND a.qy='${qy}'  `
                } else {
                    where += `  AND a.sq LIKE '${sq}%'   `
                }

            } else if (qy && qy != "") {
                where += `  AND a.qy='${qy}'  `
            } else {
                if (city) {
                    where += `  AND a.sq LIKE '${city}%'   `
                } else {
                    where += `  AND a.sq LIKE '广州%'  `
                }
            }
        }


        //专题
        if (theme_id) {
            where += ` AND  b.theme_id=${theme_id} `
        }
        //楼盘标签
        if (labelId) {
            where += ` AND  g.label_id=${labelId} `
        }
        //居室
        if (js && js != "0") {
            if (js == "5") {
                where += ` AND e.id >=${js}  `
            } else {
                where += ` AND e.id =${js}  `
            }

        }
        //参考总价
        if (minZj && maxZj) {
            // a.total_min minCkzj,a.total_max maxCkzj,a.mianji_min minJzmj,a.mianji_max maxJzmj
            if (maxZj == "不限") {
                where += `  AND a.total_min > ${minZj}  `
            } else {
                where += `  AND a.total_min > ${minZj} AND a.total_max < ${maxZj}  `
            }

        } else if (minZj) {
            let str = minZj.split("-")
            if (str.length == 2) {
                maxZj = str[1]
                minZj = str[0]
                if (!maxZj || maxZj == "不限") {
                    where += `  AND a.total_min > ${minZj}  `
                } else {
                    where += `  AND a.total_min > ${minZj} AND a.total_max < ${maxZj}  `
                }
            }
        }


        r.sq = sq
        r.qy = qy
        r.city = city


        //参考单价
        if (minDj) {
            let str = minDj.split("-")
            if (str.length == 2) {
                if (str[1] == "不限") {
                    minDj = str[0] * 10000
                    where += `   AND a.xsjg > ${minDj}  `
                } else {
                    maxDj = str[1] * 10000
                    minDj = str[0] * 10000
                    where += `   AND a.xsjg BETWEEN ${minDj} AND ${maxDj}  `
                }
            }
            // return {'数组':str}
            // if(maxDj=="不限"){
            //     where+=`  and and a.xsjg > ${minDj}  `
            // }else{
            //     where+=`  and and a.xsjg BETWEEN ${minDj} and ${maxDj}  `
            // }

        }

        //参考面积
        if (minMj) {
            // a.total_min minCkzj,a.total_max maxCkzj,a.mianji_min minJzmj,a.mianji_max maxJzmj
            let str = minMj.split("-")
            if (str.length == 2) {
                maxMj = str[1]
                minMj = str[0]
                if (maxMj == "不限") {
                    where += `  AND a.mianji_min > ${minMj}  `
                } else {
                    where += ` AND a.mianji_min > ${minMj} AND a.mianji_max < ${maxMj}  `
                }
            }
            // if(maxMj=="不限"){
            //     where+=`  and d.jzmj > ${minMj}  `
            // }else{
            //     where+=`  and d.jzmj BETWEEN ${minMj} and ${maxMj}  `
            // }

        }

        //楼盘商住区分
        // lx=1
        if (lx && lx != '') {
            if (lx == "住宅") {
                where += `   AND f.szqf <> 1  `
            }
            if (lx == "商办") {
                where += `   AND f.szqf <> 2  `
            }

            // or+=` or f.szqf=0 `
        }

        //销售状态
        if (smqk && smqk != '') {
            if (smqk == "在售") {
                where += `   AND a.xszt=0  `
            } else if (smqk == "待售") {
                where += `   AND a.xszt=1  `
            } else if (smqk == "售完") {
                where += `   AND a.xszt=2  `
            } else if (smqk == "出租") {
                where += `   AND a.xszt=3  `
            } else if (smqk == "其它") {
                where += `   AND a.xszt=4  `
            } else if (smqk == '不限') {

            }

        }

        //项目特色
        if (ts && ts != '') {
            where += `   AND a.xmts LIKE '%${ts}%'  `
        }

        //开发商
        if (kfs && kfs != '') {
            where += `   AND f.name='${kfs}'  `
        }

        sql_home_base += where + or + ` GROUP BY a.id `

        //排序
        if (orderBy) {
            if (orderBy == "1") {
                sql_home_base += ` ORDER BY a.xsjg`
            } else if (orderBy == "2") {
                sql_home_base += ` ORDER BY minCkzj`
            }
        }

        //分页
        if (page) {
            let pageNo = 0
            if (num) {
                pageNo = (page - 1) * num
            } else {
                num = 10
                pageNo = (page - 1) * num
            }
            sql_home_base += ` LIMIT ${pageNo},${num} ;SELECT FOUND_ROWS() num;`
        } else {
            sql_home_base += ` LIMIT 0,10;SELECT FOUND_ROWS() num; `
        }

        let result_home_base = yield this._daoModel.query(sql_home_base);
        let arrHomeBase = result_home_base.rows[0]
        let homeBaseCount = result_home_base.rows[1]
        r.homeBaseCount = homeBaseCount[0].num
        // return { code: 1, successed: true, rows: r,arrHomeBase:arrHomeBase }
        let arrHomeBaseId = []
        let arrFavorID = [] //接收收藏的楼盘id
        //收藏楼盘标识
        if (uid) {
            //获取手机号
            let sqlUser_mobile = `SELECT user_id,user_mobile FROM crm_user WHERE user_id='${uid}'`
            let resultUser_mobile = yield this._daoModel.query(sqlUser_mobile);
            let user_mobileArr = resultUser_mobile.rows[0]
            let userMobile = user_mobileArr.user_mobile;
            let sqlFavorItem = ``;
            if (userMobile) {
                sqlFavorItem = `SELECT a.pid FROM home_favor_item a WHERE a.uid in (SELECT user_id FROM crm_user WHERE user_mobile=(SELECT user_mobile FROM crm_user WHERE user_id='${uid}'))`
            } else {
                sqlFavorItem = `SELECT a.pid FROM home_favor_item a WHERE a.uid='${uid}'`
            }
            let resultFavorItem = yield this._daoModel.query(sqlFavorItem);
            arrFavorID = resultFavorItem.rows
            r.arrFavorItem = arrFavorID
        }
        for (let i = 0; i < arrHomeBase.length; i++) {
            if (arrHomeBase[i].pics) {
                let a = arrHomeBase[i].pics.substring(0, 4)
                //判断有没有http前缀
                if (a != 'http') {
                    arrHomeBase[i].pics = httpHead + arrHomeBase[i].pics
                }
            }
            if (arrHomeBase[i].xsjg == 0) {
                arrHomeBase[i].xsjg = '暂无均价'
            } else {
                let a = arrHomeBase[i].xsjg
                arrHomeBase[i].xsjg = a + '元/m²'
            }


            //查询最大建筑面积、参考总价和最小建筑面积、参考总价
            let ttid = arrHomeBase[i].id
            let sql_maxAndMin = `SELECT total_min minCkzj,total_max maxCkzj,mianji_min minJzmj,mianji_max maxJzmj FROM home_base WHERE id=${ttid}`;
            let result_maxAndMin = yield this._daoModel.query(sql_maxAndMin);
            let arrMaxAndMin = result_maxAndMin.rows[0]
            // arrHomeBase.jzmjAndCkzj = arrMaxAndMin
            let arrMaxAndMinXXX = arrMaxAndMin //##待删除
            let strJzmj = '待定'
            let strCkzj = '待定'
            if (arrMaxAndMin) {
                //建筑面积 
                if (arrMaxAndMin.minJzmj > 0 && arrMaxAndMin.maxJzmj > 0) {
                    strJzmj = parseInt(arrMaxAndMin.minJzmj) + '-' + parseInt(arrMaxAndMin.maxJzmj) + 'm²'
                }
                //参考总价
                if (arrMaxAndMin.minCkzj > 0 && arrMaxAndMin.maxCkzj > 0) {
                    strCkzj = parseInt(arrMaxAndMin.minCkzj) + '-' + parseInt(arrMaxAndMin.maxCkzj) + '万'
                }


                //建筑面积 
                if (arrMaxAndMinXXX.minJzmj > 0 && arrMaxAndMinXXX.maxJzmj > 0) {
                    arrMaxAndMinXXX.minJzmj = parseInt(arrMaxAndMinXXX.minJzmj)
                    arrMaxAndMinXXX.maxJzmj = parseInt(arrMaxAndMinXXX.maxJzmj)
                } else {
                    arrMaxAndMinXXX.minJzmj = '待定'
                    arrMaxAndMinXXX.maxJzmj = '待定'
                }
                //参考总价
                if (arrMaxAndMinXXX.minCkzj > 0 && arrMaxAndMinXXX.maxCkzj > 0) {
                    arrMaxAndMinXXX.minCkzj = parseInt(arrMaxAndMinXXX.minCkzj)
                    arrMaxAndMinXXX.maxCkzj = parseInt(arrMaxAndMinXXX.maxCkzj)
                } else {
                    arrMaxAndMinXXX.minCkzj = ''
                    arrMaxAndMinXXX.maxCkzj = ''
                }
            }

            arrHomeBase[i].jzmjAndCkzj = arrMaxAndMinXXX;
            arrHomeBase[i].strJzmj = strJzmj
            arrHomeBase[i].strCkzj = strCkzj


            //查询楼盘标签
            arrHomeBaseId.push(arrHomeBase[i].id)
            //标识用户是否收藏
            arrHomeBase[i].isSC = false
            for (let a = 0; a < arrFavorID.length; a++) {
                let rxid = arrHomeBase[i].id
                let fid = arrFavorID[a].pid
                if (rxid == fid) {
                    arrHomeBase[i].isSC = true
                }
            }
        }
        //查询楼盘标签
        if (arrHomeBaseId.length > 0) {
            let homeBaseIdArr = '('
            for (let i = 0; i < arrHomeBaseId.length; i++) {
                if (i == 0) {
                    homeBaseIdArr += arrHomeBaseId[i]
                } else {
                    homeBaseIdArr += ',' + arrHomeBaseId[i]
                }
            }
            homeBaseIdArr += ')'
            let sql_homeLabel = `SELECT a.label_id,a.label_name,b.home_id
        FROM bas_label a INNER JOIN home_label b ON a.label_id=b.label_id
        WHERE a.label_disabled=0 AND b.home_id IN ${homeBaseIdArr}`;
            let result_homeLabel = yield this._daoModel.query(sql_homeLabel);
            let arrHomeLabel = result_homeLabel.rows

            for (let i = 0; i < arrHomeBase.length; i++) {
                let hbId = arrHomeBase[i].id
                let homeLabelList = []
                let homeLabel = {}
                for (let a = 0; a < arrHomeLabel.length; a++) {
                    let home_id = arrHomeLabel[a].home_id
                    if (hbId == home_id) {
                        homeLabel = {
                            "label_id": arrHomeLabel[a].label_id,
                            "label_name": arrHomeLabel[a].label_name,
                            "home_id": arrHomeLabel[a].home_id
                        };
                        homeLabelList.push(homeLabel)
                    }
                }
                arrHomeBase[i].arrHomeLabel = homeLabelList
            }

            //楼盘信息添加楼盘居室
            let sql_homejjx = `SELECT distinct a.id,b.jjx
            FROM home_base a INNER JOIN home_base_hx b ON b.pid=a.id
            WHERE b.del=0  AND a.id in ${homeBaseIdArr} `;
            let result_homejjx = yield this._daoModel.query(sql_homejjx);
            let arrHomeJS = result_homejjx.rows
            // r.arrHomeJSTest=arrHomeJS
            for (let i = 0; i < arrHomeBase.length; i++) {
                let hbId = arrHomeBase[i].id
                let homeJSList = []
                let homeJS = {}
                for (let a = 0; a < arrHomeJS.length; a++) {
                    let home_id = arrHomeJS[a].id
                    if (hbId == home_id) {
                        homeJS = {
                            "id": arrHomeJS[a].id,
                            "jjx": arrHomeJS[a].jjx
                        };
                        homeJSList.push(homeJS)
                    }
                }
                arrHomeBase[i].arrHomeJS = homeJSList
            }


            //楼盘信息添加楼盘居室
            let sql_homelphx = `SELECT distinct a.pid,b.id,b.name
            FROM home_base_hx a INNER JOIN home_lphx b ON b.id=a.lphx_id
            WHERE a.del=0 AND b.del=0  AND a.pid IN ${homeBaseIdArr}`;
            let result_homelphx = yield this._daoModel.query(sql_homelphx);
            let arrHomeLphx = result_homelphx.rows
            for (let i = 0; i < arrHomeBase.length; i++) {
                let hbId = arrHomeBase[i].id
                let homeJSList = []
                let homeJS = {}
                for (let a = 0; a < arrHomeLphx.length; a++) {
                    let home_id = arrHomeLphx[a].pid
                    let lpId = arrHomeLphx[a].id
                    if (hbId == home_id && lpId != 0) {
                        homeJS = {
                            "id": arrHomeLphx[a].pid,
                            "lphxName": arrHomeLphx[a].name
                        };
                        homeJSList.push(homeJS)
                    }
                }
                if (homeJSList.length == 0) {
                    homeJSList.push("暂无")
                }
                arrHomeBase[i].arrHomeLphx = homeJSList
            }


            //每个楼盘添加楼盘户型信息
            // for (let i1 = 0; i1 < arrHomeBaseId.length; i1++) {
            //     let id=arrHomeBaseId[i1]
            //     //获取户型信息
            //     let sql_homeLphx = `select a.id,a.jjx,a.jzmj,a.ckzj,b.path,c.name,a.xszt
            //     from home_base_hx a
            //     INNER JOIN source_list b on b.lphx_id=a.id
            //     INNER JOIN home_lphx c on c.id=a.lphx_id
            //     where a.pid=${id} and lppic_type=0 and source_type=1 and showit=1`;
            //     let result_homeLphx = yield this._daoModel.query(sql_homeLphx);
            //     let arrHomeLphx = result_homeLphx.rows
            //     for (let i = 0; i < arrHomeLphx.length; i++) {
            //         if (arrHomeLphx[i].path) {
            //             let a = arrHomeLphx[i].path.substring(0, 4)
            //             //判断有没有http前缀
            //             if (a != 'http') {
            //                 arrHomeLphx[i].path = httpHead + arrHomeLphx[i].path
            //             }
            //         }
            //     }
            //     // r.arrHomeLphx = arrHomeLphx

            //     //查询户型分类及数量
            //     let sql_lphxName = `select c.id,c.name,count(c.name) num from home_base a INNER JOIN home_base_hx b on a.id=b.pid  INNER JOIN home_lphx c on b.lphx_id=c.id where a.id=${id} GROUP BY c.id`;
            //     let result_lphxName = yield this._daoModel.query(sql_lphxName);
            //     let arrLphxName = result_lphxName.rows
            //     let all = { "id": 0, "name": "全部", "num": arrHomeLphx.length, "list": arrHomeLphx }
            //     let allLphxName = []
            //     allLphxName.push(all)
            //     //封装楼盘户型分类数据
            //     for (let i = 0; i < arrLphxName.length; i++) {
            //         let list = []
            //         let name1 = arrLphxName[i].name
            //         for (let z = 0; z < arrHomeLphx.length; z++) {
            //             let name2 = arrHomeLphx[z].name
            //             if (name1 == name2) {
            //                 list.push(arrHomeLphx[z])
            //             }
            //         }
            //         arrLphxName[i].list = list
            //         if (list.length > 0) {
            //             allLphxName.push(arrLphxName[i])
            //         }
            //     }
            //     //添加到具体每个楼盘
            //     for (let i = 0; i < arrHomeBase.length; i++) {
            //         let hbId = arrHomeBase[i].id
            //         if(hbId==id){
            //             arrHomeBase[i].arrLphxName = allLphxName
            //         }  
            //     }
            // }
        }
        r.HomeBaseList = arrHomeBase


        // 返回楼盘标签
        let sql_label = "SELECT label_id,label_name FROM bas_label WHERE parent_id=1 AND label_disabled=0 LIMIT 10";
        let result_label = yield this._daoModel.query(sql_label);
        let label = result_label.rows
        r.labelList = label

        // //查询区域
        // let sql_qy=`select district_name,ext_field2 lat,ext_field3 lon from bas_district where parent_id=(select district_id from bas_district where district_name='广州市')`;
        // if(city){
        //     sql_qy = `select district_name,ext_field2 lat,ext_field3 lon from bas_district where parent_id=(select district_id from bas_district where district_name='${city}')`;
        // }

        // let result_qy = yield this._daoModel.query(sql_qy);
        // let arrHomeBaseQy = result_qy.rows
        // r.arrHomeBaseQy = arrHomeBaseQy

        //查询区域
        let sql_qy = `SELECT district_name,ext_field2 lat,ext_field3 lon FROM bas_district WHERE parent_id=(SELECT district_id FROM bas_district WHERE district_name='广州市')`;
        if (city) {
            sql_qy = `SELECT district_name,ext_field2 lat,ext_field3 lon FROM bas_district WHERE parent_id=(SELECT district_id FROM bas_district WHERE district_name='${city}')`;
        }
        let result_qy = yield this._daoModel.query(sql_qy);
        let arrHomeBaseQy = result_qy.rows
        for (let n = 0; n < arrHomeBaseQy.length; n++) {
            let maxJzmj = 0;
            let minJzmj = 0;
            let maxCkzj = 0;
            let minCkzj = 0;
            let num = 0;
            let disname = arrHomeBaseQy[n].district_name;
            let sql_qy_homebase = `SELECT  MIN(a.mianji_min) minmj,MAX(a.mianji_max) maxmj,MIN(a.total_min) minzj,MAX(a.total_max) maxzj
            FROM home_base a
            LEFT JOIN home_jzlx c ON c.id=a.jzlx_id
            LEFT JOIN home_wylx f ON f.id=a.wylx_id
            WHERE  a.sq='${city}'   AND a.qy='${disname}'  AND  a.del=0 AND  c.del=0   AND f.del=0 AND a.mianji_min <> 0 AND a.total_min <> 0;
            SELECT  COUNT(1) num
            FROM home_base a
            LEFT JOIN home_jzlx c ON c.id=a.jzlx_id
            LEFT JOIN home_wylx f ON f.id=a.wylx_id
            WHERE  a.sq='${city}'   AND a.qy='${disname}'  AND  a.del=0 AND  c.del=0   AND f.del=0;`;
            let result_qy_homebase = yield this._daoModel.query(sql_qy_homebase);
            let arrResult1 = result_qy_homebase.rows[0]
            let arrResult2 = result_qy_homebase.rows[1]
            let maxmj = arrResult1[0].maxmj;
            let minmj = arrResult1[0].minmj;
            let maxzj = arrResult1[0].maxzj;
            let minzj = arrResult1[0].minzj;
            if (maxmj) {
                maxJzmj = maxmj;
            }
            if (minmj) {
                minJzmj = minmj;
            }
            if (maxzj) {
                maxCkzj = maxzj;
            }
            if (minzj) {
                minCkzj = minzj;
            }
            num = arrResult2[0].num;
            arrHomeBaseQy[n].maxJzmj = maxJzmj;
            arrHomeBaseQy[n].minJzmj = minJzmj;
            arrHomeBaseQy[n].maxCkzj = maxCkzj;
            arrHomeBaseQy[n].minCkzj = minCkzj;
            arrHomeBaseQy[n].num = num;
        }
        r.arrHomeBaseQy = arrHomeBaseQy


        //查询开发商
        let sql_kfs = `SELECT name FROM home_kfs WHERE id<>0 AND del=0 LIMIT 15`;
        let result_kfs = yield this._daoModel.query(sql_kfs);
        let arrHomeBaseKfs = result_kfs.rows
        r.arrHomeBaseKfs = arrHomeBaseKfs

        let dz = ` AND a.sq = '广州市' `;

        if (city) {
            dz = ` AND a.sq LIKE '${city}%' `
        }
        if (sq) {
            dz = ` AND a.sq LIKE '${sq}%' `
            // if(qy){
            //     dz=` and a.sq = '${sq}' and a.qy='${qy}'`
            // }
        }

        //热销                                                                                      
        let sql_rx_home_base = `SELECT a.id,a.pics,a.qy,a.name,a.address,a.qy,a.xsjg,a.lon,a.lat,a.total_min minCkzj,a.total_max maxCkzj,a.mianji_min minJzmj,a.mianji_max maxJzmj
        FROM home_base a
        INNER JOIN home_theme_item b ON a.id=b.pid
        INNER JOIN home_base_hx c ON c.pid=a.id
        WHERE b.theme_id=5
         ${dz}
         AND a.xszt='0'   AND a.del=0   GROUP BY a.id LIMIT 5`;
        let result_rx_home_base = yield this._daoModel.query(sql_rx_home_base);
        let arrRxHomeBase = result_rx_home_base.rows
        for (let i = 0; i < arrRxHomeBase.length; i++) {
            if (arrRxHomeBase[i].pics) {
                let a = arrRxHomeBase[i].pics.substring(0, 4)
                //判断有没有http前缀
                if (a != 'http') {
                    arrRxHomeBase[i].pics = httpHead + arrRxHomeBase[i].pics
                }
            }
            if (arrRxHomeBase[i].xsjg == 0) {
                arrRxHomeBase[i].xsjg = '暂无均价'
            } else {
                let a = arrRxHomeBase[i].xsjg
                arrRxHomeBase[i].xsjg = a + '元/m²'
            }
            //查询最大建筑面积、参考总价和最小建筑面积、参考总价
            let arrMaxAndMin = {
                "maxJzmj": parseInt(arrRxHomeBase[i].maxJzmj),
                "minJzmj": parseInt(arrRxHomeBase[i].minJzmj),
                "maxCkzj": arrRxHomeBase[i].maxCkzj,
                "minCkzj": arrRxHomeBase[i].minCkzj
            }
            arrRxHomeBase[i].jzmjAndCkzj = arrMaxAndMin



            //建筑面积
            let strJzmj = parseInt(arrRxHomeBase[i].minJzmj) + '-' + parseInt(arrRxHomeBase[i].maxJzmj) + 'm²'
            if (arrRxHomeBase[i].minJzmj == 0 || arrRxHomeBase[i].maxJzmj == 0 || arrRxHomeBase[i].minJzmj == "null" || arrRxHomeBase[i].maxJzmj == "null") {
                strJzmj = '待定'
            }
            arrRxHomeBase[i].strJzmj = strJzmj
            //参考总价
            let strCkzj = arrRxHomeBase[i].minCkzj + '-' + arrRxHomeBase[i].maxCkzj + '万'
            if (arrRxHomeBase[i].minCkzj == 0 || arrRxHomeBase[i].maxCkzj == 0 || arrRxHomeBase[i].minCkzj == "null" || arrRxHomeBase[i].maxCkzj == "null") {
                strCkzj = '待定'
            }
            arrRxHomeBase[i].strCkzj = strCkzj


        }
        r.RxHomeBaseList = arrRxHomeBase


        return {
            code: 1,
            successed: true,
            rows: r
        };
    }

    //修改楼盘信息经纬度
    * updateHomeBaseLonAndLat(req, res) {
        let pid = req.body.pid; //楼盘id
        let lon = req.body.lon; //'经度'
        let lat = req.body.lat; //'纬度'
        // return {pid:pid,lon:lon,lat:lat}
        let sql = `UPDATE home_base a set a.lon='${lon}',a.lat='${lat}' where a.id=${pid}`
        let result = yield this._daoModel.query(sql);
        if (result.rows.affectedRows) {
            return {
                code: 1,
                successed: true
            }
        } else {
            return {
                code: 0,
                successed: false
            }
        }
    }


    //商业贷款计算器：按贷款总额计算
    * fdSydkZeCalculator(req, res) {
        let dkbj = req.query.dkbj; //贷款本金(单位：万)       
        let hkys = req.query.hkys; //还款月数(单位：年) 
        let sdll = req.query.sdll; //商贷利率
        if (!dkbj || !hkys || !sdll) {
            return {
                code: 0,
                successed: false,
                msg: '无效参数'
            }
        }
        let bj = dkbj;
        dkbj = dkbj * 10000; //贷款本金       
        hkys = hkys * 12; //还款月数
        // sdll = sdll;//商贷利率
        let jzndl = 4.90 / 100 * sdll; //基准年贷率
        let myll = jzndl / 12; //每月利率

        //房贷计算器:等额本金
        let bxzj = 0; //本息总计
        let myhkje = 0; //每月还款金额
        let arr = []; //记录每月还款的额度
        let myyhbj = dkbj / hkys; //每月应还本金
        for (let i = 0; i < hkys; i++) {
            // 每月还款金额= （贷款本金/ 还款月数）+（本金 — 已归还本金累计额）×每月利率
            myhkje = myyhbj + (dkbj - i * myyhbj) * myll
            bxzj += myhkje
            arr.push(myhkje)
        }
        let zlx = bxzj - dkbj; //总支付利息
        let mydj = arr[0].toFixed(2) - arr[1].toFixed(2);
        let r1 = {
            "dkbj": bj,
            "hkys": hkys,
            "myhkje": arr[0].toFixed(2),
            "bxzj": bxzj.toFixed(2),
            "zlx": zlx.toFixed(2),
            "mydj": mydj.toFixed(2)
        }
        // let r1 = { "贷款本金": dkbj, "还款月数": hkys, "每月还款金额": arr[0], "本息总计": bxzj, "总利息": zlx }//测试用

        //等额本息
        // 等额本息每月还款金额=〔月利率*贷款本金*(月利率+1)^还款月数〕÷〔(1+月利率)^还款月数-1〕
        let e = Math.pow(1 + myll, hkys)
        let a = dkbj * myll * e
        let b = Math.pow(1 + myll, hkys)
        let d = a / (b - 1)
        let bxzj2 = d * hkys
        let zlx2 = bxzj2 - dkbj
        let r2 = {
            "dkbj": bj,
            "hkys": hkys,
            "myhkje": d.toFixed(2),
            "bxzj": bxzj2.toFixed(2),
            "zlx": zlx2.toFixed(2)
        }
        // let r2 = { "贷款本金": dkbj, "还款月数": hkys, "每月还款金额": d, "本息总计": bxzj2, "总利息": zlx2 }//测试用

        // return { "等额本金": r1, "等额本息": r2 }
        return {
            code: 1,
            successed: true,
            msg: '',
            "equivalentPrincipal": r1,
            "equalPrincipalAndInterest": r2
        }
    }


    //商业贷款计算器：按面积、单价计算
    * fdSydkMjCalculator(req, res) {
        let dj = req.query.dj; //单价(单位：元/平方米)       
        let mj = req.query.mj; //面积 
        let sf = req.query.sf; //首付（单位：成）
        let dkqx = req.query.dkqx; //贷款期限(单位：年) 
        let sdll = req.query.sdll; //商贷利率
        if (!dj || !mj || !sf || !dkqx || !sdll) {
            return {
                code: 0,
                successed: false,
                msg: '无效参数'
            }
        }


        // let dj = 10000;
        // let mj = 100;
        sf = sf / 10;
        let dkbj = (dj * mj) - (dj * mj * sf); //贷款本金
        let bj = dkbj / 10000.0;
        let hkys = dkqx * 12; //还款月数
        // let sdll = 1;//商贷利率
        let jzndl = 4.90 / 100 * sdll; //基准年贷率
        let myll = jzndl / 12; //每月利率

        //房贷计算器:等额本金
        let bxzj = 0; //本息总计
        let myhkje = 0; //每月还款金额
        let arr = []; //记录每月还款的额度
        let myyhbj = dkbj / hkys; //每月应还本金
        for (let i = 0; i < hkys; i++) {
            // 每月还款金额= （贷款本金/ 还款月数）+（本金 — 已归还本金累计额）×每月利率
            myhkje = myyhbj + (dkbj - i * myyhbj) * myll
            bxzj += myhkje
            arr.push(myhkje)
        }
        let zlx = bxzj - dkbj; //总支付利息
        let mydj = arr[0].toFixed(2) - arr[1].toFixed(2);
        let r1 = {
            "dkbj": bj.toFixed(2),
            "hkys": hkys,
            "myhkje": arr[0].toFixed(2),
            "bxzj": bxzj.toFixed(2),
            "zlx": zlx.toFixed(2),
            "mydj": mydj.toFixed(2)
        }
        // let r1 = { "贷款本金": dkbj, "还款月数": hkys, "每月还款金额": arr[0], "本息总计": bxzj, "总利息": zlx }//测试用

        //等额本息
        // 等额本息每月还款金额=〔月利率*贷款本金*(月利率+1)^还款月数〕÷〔(1+月利率)^还款月数-1〕
        let e = Math.pow(1 + myll, hkys)
        let a = dkbj * myll * e
        let b = Math.pow(1 + myll, hkys)
        let d = a / (b - 1)
        let bxzj2 = d * hkys
        let zlx2 = bxzj2 - dkbj
        let r2 = {
            "dkbj": bj.toFixed(2),
            "hkys": hkys,
            "myhkje": d.toFixed(2),
            "bxzj": bxzj2.toFixed(2),
            "zlx": zlx2.toFixed(2)
        }
        // let r2 = { "贷款本金": dkbj, "还款月数": hkys, "每月还款金额": d, "本息总计": bxzj2, "总利息": zlx2 }//测试用

        // return { "等额本金": r1, "等额本息": r2 }
        return {
            code: 1,
            successed: true,
            msg: '',
            "equivalentPrincipal": r1,
            "equalPrincipalAndInterest": r2
        }
    }

    //组合贷款计算器
    * fdZhdkCalculator(req, res) {

        let sdDkbj = req.query.sdDkbj; //商贷贷款本金(单位：万)       
        let gjjDkbj = req.query.gjjDkbj; //公积金贷款本金 (单位：万)
        let sdll = req.query.sdll; //商贷利率
        let gjjll = req.query.gjjll; //公积金贷款利率
        let dkqx = req.query.dkqx; //贷款期限(单位：年) 

        if (!sdDkbj || !gjjDkbj || !sdll || !gjjll || !dkqx) {
            return {
                code: 0,
                successed: false,
                msg: '无效参数'
            }
        }

        let bj = sdDkbj + gjjDkbj;
        sdDkbj = sdDkbj * 10000; //商贷贷款本金
        gjjDkbj = gjjDkbj * 10000; //公积金贷款本金
        let hkys = dkqx * 12; //还款月数
        // let sdll = 1;//商贷利率
        // let gjjll = 1;//公积金贷款利率
        let sdJzndl = 4.90 / 100 * sdll; //商贷基准年贷率
        let gjjJzndl = 0; //公积金贷款基准年贷率
        //公积金贷款利率是2015年10月24日调整并实施的，五年以上公积金贷款利率3.25%,月利率为3.25%/12，五年及以下公积金贷款利率为年利率2.75%
        if (hkys > 5 * 12) {
            gjjJzndl = 3.25 / 100 * gjjll;
        } else {
            gjjJzndl = 2.75 / 100 * gjjll;
        }
        // gjjJzndl = 3.25 / 100 * gjjll;
        let sdMyll = sdJzndl / 12; //商贷每月利率
        let gjjMyll = gjjJzndl / 12; //公积金贷款每月利率
        let dkbj = sdDkbj + gjjDkbj; //贷款本金

        //房贷计算器:商贷等额本金
        let bxzj = 0; //本息总计
        let sdmyhkje = 0; //商贷每月还款金额
        let sdarr = []; //记录每月还款的额度
        let sdmyyhbj = sdDkbj / hkys; //每月应还本金
        for (let i = 0; i < hkys; i++) {
            // 每月还款金额= （贷款本金/ 还款月数）+（本金 — 已归还本金累计额）×每月利率
            sdmyhkje = sdmyyhbj + (sdDkbj - i * sdmyyhbj) * sdMyll
            bxzj += sdmyhkje
            sdarr.push(sdmyhkje)
        }
        //房贷计算器:公积金贷款等额本金
        let gjjmyhkje = 0; //公积金每月还款金额
        let gjjarr = []; //记录每月还款的额度
        let gjjmyyhbj = gjjDkbj / hkys; //每月应还本金
        for (let i = 0; i < hkys; i++) {
            // 每月还款金额= （贷款本金/ 还款月数）+（本金 — 已归还本金累计额）×每月利率
            gjjmyhkje = gjjmyyhbj + (gjjDkbj - i * gjjmyyhbj) * gjjMyll
            bxzj += gjjmyhkje
            gjjarr.push(gjjmyhkje)
        }
        let zlx = bxzj - dkbj; //总支付利息
        let syhkje = sdarr[0] + gjjarr[0]; //首页还款金额
        let mydj = syhkje - (sdarr[1] + gjjarr[1]);
        let r1 = {
            "dkbj": bj,
            "hkys": hkys,
            "myhkje": syhkje.toFixed(2),
            "bxzj": bxzj.toFixed(2),
            "zlx": zlx.toFixed(2),
            "mydj": mydj.toFixed(2)
        }
        // let r1 = { "贷款本金": dkbj, "还款月数": hkys, "首月还款金额": syhkje.toFixed(2), "本息总计": bxzj.toFixed(2), "总利息": zlx.toFixed(2) }//测试用

        //等额本息
        // 等额本息每月还款金额=〔月利率*贷款本金*(月利率+1)^还款月数〕÷〔(1+月利率)^还款月数-1〕
        //商贷：等额本息
        let e = Math.pow(1 + sdMyll, hkys)
        let a = sdDkbj * sdMyll * e
        let b = Math.pow(1 + sdMyll, hkys)
        let d = a / (b - 1)
        //公积金贷款：等额本息
        let e1 = Math.pow(1 + gjjMyll, hkys)
        let a1 = gjjDkbj * gjjMyll * e1
        let b1 = Math.pow(1 + gjjMyll, hkys)
        let d1 = a1 / (b1 - 1)
        let hkje = d + d1
        let bxzj2 = hkje * hkys
        let zlx2 = bxzj2 - dkbj
        let r2 = {
            "dkbj": bj,
            "hkys": hkys,
            "myhkje": hkje.toFixed(2),
            "bxzj": bxzj2.toFixed(2),
            "zlx": zlx2.toFixed(2)
        }
        // let r2 = { "贷款本金": dkbj, "还款月数": hkys, "每月还款金额": hkje.toFixed(2), "本息总计": bxzj2.toFixed(2), "总利息": zlx2.toFixed(2) }//测试用

        // return { "等额本金": r1, "等额本息": r2 }
        return {
            code: 1,
            successed: true,
            msg: '',
            "equivalentPrincipal": r1,
            "equalPrincipalAndInterest": r2
        }
    }


    //购房能力评估
    * getPurchaseAbilityEvaluation(req, res) {
        let gfzj = req.query.gfzj; //可用于购房资金(单位：万)       
        let mygfzc = req.query.mygfzc; //每月购房支出(单位：元) 
        let hknx = req.query.hknx; //还款年限(单位：年)
        let mj = req.query.mj; //购房面积
        if (!gfzj || !mygfzc || !hknx || !mj) {
            return {
                code: 0,
                successed: false,
                msg: '无效参数'
            }
        }
        let r = {}
        let hkys = hknx * 12; //还款月数
        let jzndl = 4.90 / 100 * 1; //基准年贷率
        let myll = jzndl / 12; //每月利率
        let e = Math.pow(1 + myll, hkys); //(月利率+1)^还款月数
        let b = Math.pow(1 + myll, hkys); //(1+月利率)^还款月数
        let totalHousePrice = 0; //总价
        let houseUnitPrice = 0; //单价
        let num1 = mygfzc * (b - 1);
        gfzj = gfzj * 10000
        totalHousePrice = num1 / myll / e;
        totalHousePrice = totalHousePrice + gfzj
        houseUnitPrice = totalHousePrice / mj;
        r.totalHousePrice = (totalHousePrice / 10000).toFixed(2);
        r.houseUnitPrice = houseUnitPrice.toFixed(2);
        return {
            code: 1,
            successed: true,
            msg: '',
            rows: r
        }
    }

    //贷款利率
    * getLendingRate(req, res) {
        let r = {}
        r.sdjzndl = 4.90; //商贷基准年贷率
        r.gjjndls = 3.25; //公积金年贷率（五年以上）
        r.gjjndlx = 2.75; //公积金年贷率（五年及以下）
        return {
            code: 1,
            successed: true,
            msg: '',
            rows: r
        }
    }

    //房贷计算器的使用记录
    * addHomeCalculator(req, res) {
        //0、商业贷款:商贷贷款金额，商贷利率，商贷期限
        //1、公积金贷款：公积金贷款金额，公积金利率，公积金期限
        //2、组合贷款：商贷贷款金额，商贷利率，商贷期限，公积金贷款金额，公积金利率，公积金期限
        //3、商业贷款按面积/单价计算：单价，面积，首付
        //必传参数：用户id,贷款类型，还款月数，贷款总额，等额本息每月还款，等额本息总支付利息，等额本息本息总计，等额本金首月还款，等额本金总支付利息，等额本金本息总计，等额本金每月递减
        let uid = req.body.uid || ''; //char(36)  '用户id',
        let dklx = req.body.dklx; //int(1) '贷款类型：0、商业贷款     1、公积金贷款     2、组合贷款     3、商业贷款按面积/单价计算',
        let sd_dkje = req.body.sd_dkje || '0'; //double(13,4)  '商贷贷款金额：万',
        let sd_ll = req.body.sd_ll || '0'; //double(4,2)  '商贷利率',
        let sd_qx = req.body.sd_qx || '0'; //int(2)  '商贷贷款期限：年',
        let gjj_dkje = req.body.gjj_dkje || '0'; //double(13,2)  '公积金贷款金额：万',
        let gjj_ll = req.body.gjj_ll || '0'; //double(4,4)  '公积金利率',
        let gjj_qx = req.body.gjj_qx || '0'; //int(2)  '公积金贷款期限：年',
        let dj = req.body.dj || '0'; //double(13,4)  '单价：元/平方米',
        let mj = req.body.mj || '0'; //double(9,2)  '面积：平方米',
        let sf = req.body.sf || '0'; //varchar(4)  '首付：？成',
        let hkys = req.body.hkys || '0'; //int(4)  '还款月数',
        let dkze = req.body.dkze || '0'; //double(13,4)  '贷款总额：万',
        let debx_myhk = req.body.debx_myhk || '0'; //double(13,4)  '等额本息每月还款：元',
        let debx_zzflx = req.body.debx_zzflx || '0'; //double(13,4)  '等额本息总支付利息：元',
        let debx_bxzj = req.body.debx_bxzj || '0'; //double(13,4)  '等额本息本息总计：元',
        let debj_syhk = req.body.debj_syhk || '0'; //double(13,4)  '等额本金首月还款：元',
        let debj_zzflx = req.body.debj_zzflx || '0'; //double(13,4)  '等额本金总支付利息：元',
        let debj_bxzj = req.body.debj_bxzj || '0'; //double(13,4)  '等额本金本息总计：元',
        let debj_mydj = req.body.debj_mydj || '0'; //double(13,4)  '等额本金每月递减：元',

        if (dklx == '0') {
            let sql = `INSERT INTO home_calculator (uid, dklx, sd_dkje, sd_ll, sd_qx, gjj_dkje, gjj_ll, gjj_qx, dj, mj, sf, hkys, dkze, debx_myhk, debx_zzflx, debx_bxzj, debj_syhk, debj_zzflx, debj_bxzj, debj_mydj)
            VALUES ('${uid}', '0', '${sd_dkje}', '${sd_ll}', '${sd_qx}', '0', '0', '0', '0', '0', '0', '${hkys}', '${dkze}', '${debx_myhk}', '${debx_zzflx}', '${debx_bxzj}', '${debj_syhk}', '${debj_zzflx}', '${debj_bxzj}', '${debj_mydj}');`
            let result = yield this._daoModel.query(sql);
            if (result.rows.affectedRows) {
                return {
                    code: 1,
                    successed: true,
                    msg: "成功"
                }
            } else {
                return {
                    code: 1,
                    successed: false,
                    msg: "失败"
                }
            }
        } else if (dklx == '1') {
            let sql = `INSERT INTO home_calculator (uid, dklx, sd_dkje, sd_ll, sd_qx, gjj_dkje, gjj_ll, gjj_qx, dj, mj, sf, hkys, dkze, debx_myhk, debx_zzflx, debx_bxzj, debj_syhk, debj_zzflx, debj_bxzj, debj_mydj)
            VALUES ('${uid}', '1', '0', '0', '0', '${gjj_dkje}', '${gjj_ll}', '${gjj_qx}', '0', '0', '0', '${hkys}', '${dkze}', '${debx_myhk}', '${debx_zzflx}', '${debx_bxzj}', '${debj_syhk}', '${debj_zzflx}', '${debj_bxzj}', '${debj_mydj}');`
            let result = yield this._daoModel.query(sql);
            if (result.rows.affectedRows) {
                return {
                    code: 1,
                    successed: true,
                    msg: "成功"
                }
            } else {
                return {
                    code: 1,
                    successed: false,
                    msg: "失败"
                }
            }
        } else if (dklx == '2') {
            let sql = `INSERT INTO home_calculator (uid, dklx, sd_dkje, sd_ll, sd_qx, gjj_dkje, gjj_ll, gjj_qx, dj, mj, sf, hkys, dkze, debx_myhk, debx_zzflx, debx_bxzj, debj_syhk, debj_zzflx, debj_bxzj, debj_mydj)
            VALUES ('${uid}', '2', '${sd_dkje}', '${sd_ll}', '${sd_qx}', '${gjj_dkje}', '${gjj_ll}', '${gjj_qx}', '0', '0', '0', '${hkys}', '${dkze}', '${debx_myhk}', '${debx_zzflx}', '${debx_bxzj}', '${debj_syhk}', '${debj_zzflx}', '${debj_bxzj}', '${debj_mydj}');`
            let result = yield this._daoModel.query(sql);
            if (result.rows.affectedRows) {
                return {
                    code: 1,
                    successed: true,
                    msg: "成功"
                }
            } else {
                return {
                    code: 1,
                    successed: false,
                    msg: "失败"
                }
            }
        } else if (dklx == '3') {
            let sql = `INSERT INTO home_calculator (uid, dklx, sd_dkje, sd_ll, sd_qx, gjj_dkje, gjj_ll, gjj_qx, dj, mj, sf, hkys, dkze, debx_myhk, debx_zzflx, debx_bxzj, debj_syhk, debj_zzflx, debj_bxzj, debj_mydj)
            VALUES ('${uid}', '3', '0', '0', '0', '0', '0', '0', '${dj}', '${mj}', '${sf}', '${hkys}', '${dkze}', '${debx_myhk}', '${debx_zzflx}', '${debx_bxzj}', '${debj_syhk}', '${debj_zzflx}', '${debj_bxzj}', '${debj_mydj}');`
            let result = yield this._daoModel.query(sql);
            if (result.rows.affectedRows) {
                return {
                    code: 1,
                    successed: true,
                    msg: "成功"
                }
            } else {
                return {
                    code: 1,
                    successed: false,
                    msg: "失败"
                }
            }
        } else {
            return {
                code: 0,
                successed: false,
                msg: "失败"
            }
        }


    }

    //查询楼盘动态
    * querylpdt(req, res) {
        let r = {}
        let pid = req.params.pid;
        //查询楼盘动态
        let sql_home_dyanmic = `select * from home_dynamic where pid=${pid}    and del=0   ORDER BY time DESC`;
        let result_sql_home_dyanmic = yield this._daoModel.query(sql_home_dyanmic);
        let arrHomeDyanmic = result_sql_home_dyanmic.rows
        // r.arrHomeDyanmic = arrHomeDyanmic


        let lpdtList = [] //楼盘动态
        let kpxxList = [] //开盘信息
        let jfxxList = [] //交房信息
        let zjxxList = [] //证件信息
        arrHomeDyanmic.forEach(element => {
            let hdtype = element.type
            element.time = (date.format(element.time, 'YYYY-MM-DD')) + 'T';
            element.start_time = (date.format(element.start_time, 'YYYY-MM-DD')) + 'T';
            if (hdtype == 0) {
                lpdtList.push(element)
            } else if (hdtype == 1) {
                zjxxList.push(element)
            } else if (hdtype == 2) {
                kpxxList.push(element)
            } else if (hdtype == 3) {
                jfxxList.push(element)
            }
        });
        r.lpdtList = lpdtList
        r.kpxxList = kpxxList
        r.jfxxList = jfxxList
        r.zjxxList = zjxxList
        return {
            code: 1,
            successed: true,
            rows: r
        }
    }



    //获取楼盘相册
    * getHomeBaseAlbum(req) {
        let r = {};
        let id = req.params.pid;
        //从配置类获取请求头前缀
        let httpHead = config.appsetting.picHead
        //从配置类获取楼盘图片类型
        let sourceLppicTypeList = config.sourceLppicTypeList
        //清空缓存从配置类获取楼盘图片类型
        for (let a = 0; a < sourceLppicTypeList.length; a++) {
            //前端用来判断
            sourceLppicTypeList[a].isActive = false
            sourceLppicTypeList[a].list = []
        }

        //获取楼盘图片
        let sqlImageList = `select path,img,lppic_type from source_list a where pid=${id} and source_type=1	and showit=1 AND del='0' `;
        let result_imageList = yield this._daoModel.query(sqlImageList);
        let arrImageList = result_imageList.rows
        for (let i = 0; i < arrImageList.length; i++) {
            if (arrImageList[i].path) {
                let a = arrImageList[i].path.substring(0, 4)
                //判断有没有http前缀
                if (a != 'http') {
                    arrImageList[i].path = httpHead + arrImageList[i].path
                }
            }
            for (let a = 0; a < sourceLppicTypeList.length; a++) {
                if (sourceLppicTypeList[a].id == arrImageList[i].lppic_type) {
                    sourceLppicTypeList[a].list.push(arrImageList[i])
                }
            }

        }
        //获取楼盘图片分类数据
        r.sourceLppicTypeList = sourceLppicTypeList
        // r.imageList = arrImageList
        //获取楼盘图片数量
        r.imageListLength = arrImageList.length
        return {
            code: 1,
            successed: true,
            rows: r
        };
    }



    * addUserYhqQa(req, res) {
        let params = req.body.params;
        let que = params.que;
        let note = params.note;
        let uid = params.uid;
        let phone = params.phone;
        // return {"que":que,"note":note,"params":params}
        if (que || note) {
            let sql = `INSERT into crm_user_yhq_qa(que,note,phone) VALUES('${que}','${note}','${phone}')`
            if (uid) {
                sql = `INSERT into crm_user_yhq_qa(que,note,creater,phone) VALUES('${que}','${note}','${uid}','${phone}')`
            }
            let result = yield this._daoModel.query(sql);
            if (result.rows.affectedRows) {
                return {
                    code: 1,
                    successed: true,
                    msg: "成功"
                }
            } else {
                return {
                    code: 1,
                    successed: false,
                    msg: "失败"
                }
            }
        } else {
            return {
                code: 0,
                successed: false,
                msg: "失败"
            }
        }


    }


    //查询广州分区楼盘
    * querygzfqlp(req, res) {
        let r = {}
        let city = '深圳市'
        //查询区域
        let sql_qy = `select district_name,ext_field2 lat,ext_field3 lon from bas_district where parent_id=(select district_id from bas_district where district_name='广州市')`;
        if (city) {
            sql_qy = `select district_name,ext_field2 lat,ext_field3 lon from bas_district where parent_id=(select district_id from bas_district where district_name='${city}')`;
        }
        let result_qy = yield this._daoModel.query(sql_qy);
        let arrHomeBaseQy = result_qy.rows
        for (let n = 0; n < arrHomeBaseQy.length; n++) {
            let maxJzmj = 0;
            let minJzmj = 0;
            let maxCkzj = 0;
            let minCkzj = 0;
            let num = 0;
            let disname = arrHomeBaseQy[n].district_name;
            let sql_qy_homebase = `select  MIN(a.mianji_min) minmj,MAX(a.mianji_max) maxmj,MIN(a.total_min) minzj,MAX(a.total_max) maxzj
            from home_base a
            LEFT JOIN home_jzlx c on c.id=a.jzlx_id
            LEFT JOIN home_wylx f on f.id=a.wylx_id
            where  a.sq='${city}'   and a.qy='${disname}'  and  a.del=0 and  c.del=0   and f.del=0 and a.mianji_min <> 0 and a.total_min <> 0;
            select  COUNT(1) num
            from home_base a
            LEFT JOIN home_jzlx c on c.id=a.jzlx_id
            LEFT JOIN home_wylx f on f.id=a.wylx_id
            where  a.sq='${city}'   and a.qy='${disname}'  and  a.del=0 and  c.del=0   and f.del=0;`;
            let result_qy_homebase = yield this._daoModel.query(sql_qy_homebase);
            let arrResult1 = result_qy_homebase.rows[0]
            let arrResult2 = result_qy_homebase.rows[1]
            let maxmj = arrResult1[0].maxmj;
            let minmj = arrResult1[0].minmj;
            let maxzj = arrResult1[0].maxzj;
            let minzj = arrResult1[0].minzj;
            if (maxmj) {
                maxJzmj = maxmj;
            }
            if (minmj) {
                minJzmj = minmj;
            }
            if (maxzj) {
                maxCkzj = maxzj;
            }
            if (minzj) {
                minCkzj = minzj;
            }
            num = arrResult2[0].num;
            arrHomeBaseQy[n].maxJzmj = maxJzmj;
            arrHomeBaseQy[n].minJzmj = minJzmj;
            arrHomeBaseQy[n].maxCkzj = maxCkzj;
            arrHomeBaseQy[n].minCkzj = minCkzj;
            arrHomeBaseQy[n].num = num;
        }
        r.arrHomeBaseQy = arrHomeBaseQy
        return {
            code: 1,
            successed: true,
            rows: r
        }
    }



    //按名字返回楼盘
    * getQueryName(req, res) {
        let name = req.query.name;
        let r = {}
        //查询区域
        let sql = `SELECT id,name FROM home_base WHERE del='0' AND name LIKE '%${name}%';`;
        let result = yield this._daoModel.query(sql);
        let homeBaseList = result.rows
        r.homeBaseList = homeBaseList
        return {
            code: 1,
            successed: true,
            rows: r
        }
    }

    //楼盘对比
    * getHomeBaseContrast(req, res) {
        let r = {}
        let ids = req.query.idArr;
        let idArr = JSON.parse(ids);
        console.log("=====================" + idArr)
        let uid = req.query.uid || '';
        let idArrStr = '';
        let pid1 = '';
        let pid2 = '';
        let pid3 = '';
        for (let i = 0; i < idArr.length; i++) {
            if (i == 0) {
                pid1 = idArr[i];
                idArrStr += idArr[i];
            } else if (i == 1) {
                pid2 = idArr[i];
                idArrStr += ',' + idArr[i];
            } else if (i == 2) {
                pid3 = idArr[i];
                idArrStr += ',' + idArr[i];
            } else {
                idArrStr += ',' + idArr[i];
            }
        }
        if (idArrStr == '') {
            return {
                code: 0,
                successed: true,
                rows: r
            }
        }
        if (pid2 != '') {
            let today = date.format(new Date(), 'YYYY-MM-DD HH:mm:ss'); //当前时间
            let sql = `INSERT INTO home_contrast (uid, pid1, pid2, pid3, create_date) VALUES ('${uid}', '${pid1}', '${pid2}', '${pid3}', '${today}');`;
            let result = yield this._daoModel.query(sql);
        }

        //从配置类获取请求头前缀
        let httpHead = config.appsetting.picHead
        //查询区域
        let sql = `SELECT a.id,a.name,a.phone,a.pics,a.xsjg,a.xszt,b.name wylxname,a.sq,a.qy,a.address,a.desc_zhoubian,a.kpsj,a.smzh,a.mianji_min,a.mianji_max,c.name kfsname,a.wygs,a.wyf,d.name jzlxname,a.status_gongcheng,a.cqnx,a.rjl,a.lhl,a.zhs,a.cwqk,a.zxqk
        FROM home_base a
        LEFT JOIN home_wylx b ON b.id=a.wylx_id
        LEFT JOIN home_kfs c ON c.id=a.kfs_id
        LEFT JOIN home_jzlx d ON d.id=a.jzlx_id
        WHERE a.id IN (${idArrStr}) ORDER BY a.id ASC;`;
        let result = yield this._daoModel.query(sql);
        let arrHomeBase = result.rows
        for (let i = 0; i < arrHomeBase.length; i++) {
            if (arrHomeBase[i].pics) {
                let a = arrHomeBase[i].pics.substring(0, 4)
                //判断有没有http前缀
                if (a != 'http') {
                    arrHomeBase[i].pics = httpHead + arrHomeBase[i].pics
                }
            }
            let sql2 = `SELECT DISTINCT a.pid,b.name FROM home_base_hx a INNER JOIN home_lphx b ON b.id=a.lphx_id WHERE a.del='0' AND b.del='0' AND a.pid='${arrHomeBase[i].id}' ORDER BY b.id;`;
            let result2 = yield this._daoModel.query(sql2);
            let arrHomeLphx = result2.rows
            let lpjs = ''
            for (let a = 0; a < arrHomeLphx.length; a++) {
                if (a == 0) {
                    lpjs += arrHomeLphx[a].name
                } else {
                    lpjs += ',' + arrHomeLphx[a].name
                }

            }
            arrHomeBase[i].lpjs = lpjs
        }
        r.arrHomeBase = arrHomeBase
        return {
            code: 1,
            successed: true,
            rows: r
        }
    }

    //猜你喜欢楼盘
    * getInterestHomeBase(req, res) {
        let r = {}
        //从配置类获取请求头前缀
        let httpHead = config.appsetting.picHead
        let city = req.query.city || '广州市';
        //查询区域
        let sql = `SELECT a.id,a.name,a.pics,a.sq,a.qy,a.xsjg,a.mianji_min,a.mianji_max,b.name wylxname FROM home_base a INNER JOIN home_wylx b ON b.id=a.wylx_id WHERE a.sq='${city}' AND a.del='0' AND a.xszt='0' ORDER BY  RAND()  LIMIT 8;`;
        let result = yield this._daoModel.query(sql);
        let arrHomeBase = result.rows
        for (let i = 0; i < arrHomeBase.length; i++) {
            if (arrHomeBase[i].pics) {
                let a = arrHomeBase[i].pics.substring(0, 4)
                //判断有没有http前缀
                if (a != 'http') {
                    arrHomeBase[i].pics = httpHead + arrHomeBase[i].pics
                }
            }

            if (arrHomeBase[i].xsjg && arrHomeBase[i].xsjg != '0') {
                arrHomeBase[i].xsjg = arrHomeBase[i].xsjg + '元/m²'
            } else {
                arrHomeBase[i].xsjg = '暂无报价'
            }

            if (arrHomeBase[i].mianji_min != '0' && arrHomeBase[i].mianji_max != '0') {
                arrHomeBase[i].mianji = arrHomeBase[i].mianji_min + '-' + arrHomeBase[i].mianji_max + 'm²'
            } else {
                arrHomeBase[i].mianji = '暂无'
            }

        }
        r.arrHomeBase = arrHomeBase
        return {
            code: 1,
            successed: true,
            rows: r
        }
    }

    //猜你喜欢楼盘mini
    * getMiniInterestHomeBase(req, res) {
        let r = {}
        let idsArr = req.query.idsArr;
        console.log("---------------------" + idsArr)
        let idArr = JSON.parse(idsArr);
        console.log("=====================" + idArr)
        let str = ``
        for (let i = 0; i < idArr.length; i++) {
            str += ` AND a.id<>'${idArr[i]}' `
        }
        //从配置类获取请求头前缀
        let httpHead = config.appsetting.picHead
        let city = req.query.city || '广州市';
        //查询区域
        let sql = `SELECT a.id,a.name,a.pics,a.sq,a.qy,a.xsjg,a.mianji_min,a.mianji_max FROM home_base a  WHERE a.sq='${city}' AND a.del='0' AND a.xszt='0' ${str} ORDER BY  RAND()  LIMIT 8;`;
        let result = yield this._daoModel.query(sql);
        let arrHomeBase = result.rows
        for (let i = 0; i < arrHomeBase.length; i++) {
            if (arrHomeBase[i].pics) {
                let a = arrHomeBase[i].pics.substring(0, 4)
                //判断有没有http前缀
                if (a != 'http') {
                    arrHomeBase[i].pics = httpHead + arrHomeBase[i].pics
                }
            }

            if (arrHomeBase[i].xsjg && arrHomeBase[i].xsjg != '0') {
                // arrHomeBase[i].xsjg = arrHomeBase[i].xsjg + '元/m²'
            } else {
                arrHomeBase[i].xsjg = '--'
            }

            if (arrHomeBase[i].mianji_min != '0' && arrHomeBase[i].mianji_max != '0') {
                arrHomeBase[i].strJzmj = arrHomeBase[i].mianji_min + '-' + arrHomeBase[i].mianji_max + 'm²'
            } else {
                arrHomeBase[i].strJzmj = '暂无'
            }


            //查询楼盘标签
            let id = arrHomeBase[i].id
            let sql_homeLabel1 = `SELECT a.label_id,a.label_name FROM bas_label a INNER JOIN home_label b ON a.label_id=b.label_id WHERE a.label_disabled=0 AND b.home_id=${id}`;
            let result_homeLabel1 = yield this._daoModel.query(sql_homeLabel1);
            let arrHomeLabel1 = result_homeLabel1.rows
            arrHomeBase[i].arrHomeLabel1 = arrHomeLabel1
            // r.homeBaseInfo = arrHomeBase
        }
        r.arrHomeBase = arrHomeBase
        return {
            code: 1,
            successed: true,
            rows: r
        }
    }

    //猜你喜欢楼盘mini
    * updatevideo(req, res) {

        let sql = `SELECT id,vids FROM home_base WHERE vids is NULL`;
        let result = yield this._daoModel.query(sql);
        let arrHomeBase = result.rows
        for (let i = 0; i < arrHomeBase.length; i++) {
            let id = arrHomeBase[i].id
            // 获取楼盘视频信息
            let sql_video = `SELECT path,img,lppic_type FROM source_list a WHERE pid=${id} AND source_type=2  AND lppic_type=3  AND showit=1  AND del='0' ORDER BY id LIMIT 1`;
            let result_video = yield this._daoModel.query(sql_video);
            let arrVideo = result_video.rows[0]
            if (arrVideo) {
                // 修改楼盘视频信息
                let sqlupdatevideo = `UPDATE home_base SET vids='${arrVideo.path}' WHERE id='${id}'`;
                let result_updatevideo = yield this._daoModel.query(sqlupdatevideo);
            }
        }
        return {
            code: 1,
            successed: true
        }
    }



    //帮我找房页面数据
    * getFindHomeBaseInfo(req, res) {
        let city = req.query.city || '佛山市';
        let httpHead = config.appsetting.picHead
        let r = {};
        let sql_district = `SELECT district_name FROM bas_district WHERE parent_id=(SELECT district_id FROM bas_district WHERE district_name='${city}');`
        let result_district = yield this._daoModel.query(sql_district)
        let districtList = result_district.rows
        // for (let i = 0; i < districtList.length; i++) {
        //     let len=districtList[i].district_name.length;
        //     let a = districtList[i].district_name.substring(0, len-1)
        //     districtList[i].district_name=a;
        // }
        r.districtList = districtList

        let jsList = ["一室", "二室", "三室", "四室", "五室及以上", "不限"]
        let strList = ["一个人也要住的精彩", "开启甜蜜二人世界", "拥有幸福三口之家", "两孩三代人的不二", "满足品质生活的憧憬", "又酷又温柔独立且自由"]
        let imageList = ["http://image.xinghe00.com/lppic/modelImage/f9efb1b8-bbc5-459c-9846-dc7d399236ea_1400x1050.jpg", "http://image.xinghe00.com/lppic/modelImage/4c0c3a31-89b2-467e-8567-166d22ed2af1_1400x1050.jpg", "http://image.xinghe00.com/lppic/pics/4a5ca899a936d244.jpg", "http://image.xinghe00.com/lppic/pics/8f0e2b4d66a7d637.jpg", "http://image.xinghe00.com/lppic/pics/fd006ba54fb5accf.jpg", "http://image.xinghe00.com/lppic/pics/8678ba3daa662a6a.png"]
        let sql = `SELECT COUNT(1) num FROM home_base WHERE sq='${city}';SELECT pics FROM home_base WHERE del='0' ORDER BY  RAND()  LIMIT 5;`
        let result = yield this._daoModel.query(sql)
        let result1 = result.rows[0]
        // r.result1=result1
        let result2 = result.rows[1]
        r.num = result1[0].num
        for (let i = 0; i < result2.length; i++) {
            if (result2[i].pics) {
                let a = result2[i].pics.substring(0, 4)
                //判断有没有http前缀
                if (a != 'http') {
                    result2[i].pics = httpHead + result2[i].pics
                }
            }
        }
        r.imagesList = result2

        let arr = [];

        for (let i = 0; i < jsList.length; i++) {
            let clas = {}
            clas.img = imageList[i];
            clas.js = jsList[i];
            clas.str = strList[i];
            arr.push(clas)
        }
        r.jsAndImageList = arr
        return {
            code: 1,
            successed: true,
            rows: r
        };
    }


    //猜你喜欢楼盘mini
    * updatevideo(req, res) {

        let sql = `SELECT id,vids FROM home_base WHERE vids is NULL`;
        let result = yield this._daoModel.query(sql);
        let arrHomeBase = result.rows
        for (let i = 0; i < arrHomeBase.length; i++) {
            let id = arrHomeBase[i].id
            // 获取楼盘视频信息
            let sql_video = `SELECT path,img,lppic_type FROM source_list a WHERE pid=${id} AND source_type=2  AND lppic_type=3  AND showit=1  AND del='0' ORDER BY id LIMIT 1`;
            let result_video = yield this._daoModel.query(sql_video);
            let arrVideo = result_video.rows[0]
            if (arrVideo) {
                // 修改楼盘视频信息
                let sqlupdatevideo = `UPDATE home_base SET vids='${arrVideo.path}' WHERE id='${id}'`;
                let result_updatevideo = yield this._daoModel.query(sqlupdatevideo);
            }
        }
        return {
            code: 1,
            successed: true
        }
    }


    //猜你喜欢楼盘mini
    * updatevideo(req, res) {

        let sql = `SELECT id,vids FROM home_base WHERE vids is NULL`;
        let result = yield this._daoModel.query(sql);
        let arrHomeBase = result.rows
        for (let i = 0; i < arrHomeBase.length; i++) {
            let id = arrHomeBase[i].id
            // 获取楼盘视频信息
            let sql_video = `SELECT path,img,lppic_type FROM source_list a WHERE pid=${id} AND source_type=2  AND lppic_type=3  AND showit=1  AND del='0' ORDER BY id LIMIT 1`;
            let result_video = yield this._daoModel.query(sql_video);
            let arrVideo = result_video.rows[0]
            if (arrVideo) {
                // 修改楼盘视频信息
                let sqlupdatevideo = `UPDATE home_base SET vids='${arrVideo.path}' WHERE id='${id}'`;
                let result_updatevideo = yield this._daoModel.query(sqlupdatevideo);
            }
        }
        return {
            code: 1,
            successed: true
        }
    }


    //获取所有的检查
    * listHB(req, res) {
        let uid = req.body.uid;
        let page = req.body.page;
        let num = req.body.num;
        let name = req.body.name;
        let ys = req.body.ys;
        let sq = req.body.sq;
        let qy = req.body.qy;
        let jd = req.body.jd;
        let startTime = req.body.startTime;
        let endTime = req.body.endTime;
        let cslx = req.body.cslx;
        

        let r = {}
        let sql_sort = `select * from home_kfs where id = '${uid}'`;
        let user = yield this._daoModel.query(sql_sort);
        let user_sort = user.rows[0].sort;
        let user_sf = user.rows[0].sf;
        let user_sq = user.rows[0].sq;
        let user_qy = user.rows[0].qy;
        let user_jd = user.rows[0].jd;

        let sql_home_base = `SELECT hb.name, hb.hxid, hb.id as hbid, hb.pic, hb.pics, hb.id_card, hb.sq, hb.qy, hb.jd, hb.address, kfs.name as kfsname,  hb.ys, hb.sh_time, hb.zg_time,  hb.note, hb.create_time FROM home_base hb   inner join home_kfs kfs on hb.kfs_id=kfs.id where hb.del=0  `;
        if(name) sql_home_base += `and hb.name like '%`+ name +`%'`;
        if(cslx) sql_home_base += `and hb.cslx like '%`+ cslx +`%'`;
        if(startTime) sql_home_base += ` and hb.sh_time >= '${startTime} 00:00:00' `;
        if(endTime) sql_home_base += ` and hb.sh_time <= '${endTime} 23:59:59' `;

        if(user_sort==0){
            sql_home_base += ` and hb.sf = '${user_sf}'`;
            if(sq) sql_home_base += ` and hb.sq = '${sq}'`;
            if(sq && qy) sql_home_base += ` and hb.qy = '${qy}'`; 
            if(sq && qy && jd) sql_home_base += ` and hb.jd = '${jd}'`;
        }
            
        if (user_sort == 1){
            sql_home_base += ` and hb.sf = '${user_sf}' and hb.sq = '${user_sq}'`;
            if(qy) sql_home_base += ` and hb.qy = '${qy}'`; 
            if(qy && jd) sql_home_base += ` and hb.jd = '${jd}'`;
        }
            
        if(user_sort== 2){
            sql_home_base += ` and hb.sf = '${user_sf}' and hb.sq = '${user_sq}' and hb.qy = '${user_qy}'`;
            if(jd) sql_home_base += ` and hb.jd = '${jd}'`;
        }
            
        if (user_sort == 3)
            sql_home_base += ` and hb.jd = '${user_jd}'`;

        //由于默认为绿色 为了避免前端搜索的时候把没检查完的都搜索出来 所以要加上第几步这个条件
         if (ys==0)
            sql_home_base +=` and  ys=0  order by hb.id desc  `
         else if (ys == 1)
             //` and hb.id in ( select DISTINCT pid  from home_base_hx where ys=1  and del=0 and djb=10 )`
             sql_home_base +=` and ys=1  order by hb.id desc `
         else if (ys == 2)
             //` and hb.id in ( select DISTINCT pid  from home_base_hx where ys=2  and del=0 and djb=10 )`
             sql_home_base +=` and ys=2  order by hb.id desc `
         else if (ys==3)
              //由于默认为绿色 ` and hb.id in ( select DISTINCT pid  from home_base_hx where ys=3  and del=0  )`
              sql_home_base +=' and ys=3 order by hb.id desc '
         else if (ys==12)
              //同时红色和黄色 ` and hb.id in ( select DISTINCT pid  from home_base_hx where (ys=1 or ys=2) and del=0  )`
              sql_home_base +=' and (ys=1 or ys=2) order by hb.ys , hb.id desc '
         else
              sql_home_base += `  order by hb.ys , hb.id desc `;

        //算出此条件下的总条数
        let resultAllCount = yield this._daoModel.query(sql_home_base);
        let allCount = resultAllCount.rows.length;

        //分页
        if (page) {
            let pageNo = 0
            if (num) {
                pageNo = (page - 1) * num
            } else {
                num = 10
                pageNo = (page - 1) * num
            }
            sql_home_base += ` LIMIT ${pageNo},${num}  `
        } else {
            sql_home_base += ` LIMIT 0,100`
        }
        let result = yield this._daoModel.query(sql_home_base);

        result.rows.map((item, index) => {
            if (item.pics.indexOf('http') == -1) {
                item.pics = config.appsetting.picHead + item.pics;
            }
            if (!item.sh_time) {
                item.sh_time="暂没排查"
            }
            if((item.ys==1 || item.ys == 2) && item.zg_time){
                let sy_time = item.zg_time;
                var a1 = Date.parse(new Date(sy_time));  //整改时间
                var a2 = Date.parse(new Date());  //当前时间
                item.zg_time = parseInt((a1-a2)/ (1000 * 60 * 60 * 24));
                if(sy_time==0) item.zg_time= 1;
            }
            if(item.ys == 3 || item.ys == 0){
                delete item.zg_time;
            }

            if(ys==0) item.ys =0;
            
        })

        let arrHomeBase = result.rows
        r.arrHomeBase = arrHomeBase
        
        return {
            code: 1,
            usort:user_sort,
            usf:user_sf,
            usq:user_sq,
            uqy:user_qy,
            ujd:user_jd,
            successed: true,
            rows: r,
            name:name,
            ys:ys,
            allCount: allCount
        }
    }

    * getInsertHb(req, res) {
        let r = {};
        let name = req.body.name;
        let fr = req.body.fr;
        let idCard = req.body.id_card;
        let uid = req.body.uid;
        let pics = req.body.pics;
        let phone = req.body.phone;
        let sf = req.body.sf;
        let sq = req.body.sq;
        let qy = req.body.qy;
        let jd = req.body.jd;
        let address = req.body.address;
        let today = date.format(new Date(), 'YYYY-MM-DD HH:mm:ss'); //当前时间
        let sql = `INSERT INTO home_base(name, fr, id_card, uid, kfs_id, check_time, pics, phone, sf, sq, qy, jd, address, xszt) VALUES ('${name}', '${fr}', '${idCard}', '${uid}', '${uid}', '${today}', '${pics}', '${phone}', '${sf}', '${sq}', '${qy}', '${jd}', '${address}', '0')`;
        let result = yield this._daoModel.query(sql);
        r   = result.rows
        return {
            code: 1,
            successed: true,
            rows: r
            
        }
    }

    //detailHb
    * detailHb(req, res) {
        let r = {};
        let hxid = req.params.hxid ;
        let sql = `SELECT hb.id as hbid, hx.id as hxid, hb.name, hb.fr, hx.ys as hxys, hx.sh_note , hx.zg_time, hx.create_time, hb.address, hx.note FROM home_base hb inner join home_base_hx hx on hb.id=hx.pid where hx.id= ` + hxid;
        let result = yield this._daoModel.query(sql);
        result.rows[0].create_time = date.format(result.rows[0].create_time, 'YYYY-MM-DD'); 
        r = result.rows[0]
        return {
            code: 1,
            successed: true,
            rows: r
        }
    }


    //detailHb
    * detailHbById(req, res) {
        let r = {};
        let id = req.params.id ;
        let sql = `SELECT * FROM home_base  where  id= ` + id;
        let result = yield this._daoModel.query(sql);
        r = result.rows[0]
        return {
            code: 1,
            successed: true,
            rows: r
        }
    }
  
    * login(req, res) {
    
        //当前时间戳
        let timespan = Math.round(new Date().getTime() / 1000);
        
        let un = req.body.un;
        let psw = req.body.psw;
        
        let r = {};
        let sql = `SELECT * FROM home_kfs where del=0 and name="` + un +'" and psw="'+ psw +'"' +' order by id desc ' ;
        let us  = yield this._daoModel.query(sql); 
        if(us.rows.length>0){
		  //修改数据库当前登录的时间戳
            yield this._daoModel.query('update home_kfs set a="' + timespan +'"'+' where id=' + us.rows[0].id ) ;

		  //修改当前a的值 用来返回前端
		  us.rows[0].a=timespan;
            return {
                code: 1,
                successed: true,
                us: us.rows[0],
                un: un 
            }
        }else{
            return {
                code: 0,
                successed: false,
                msg:"账号或密码或身份状态等错误",
                un: un
            } 
        }

    }
    
    * getHxPj(req, res) {
        let r = {};
        let hxId = req.body.hxId;
        let pj = req.body.pj;
        let sql = `SELECT `
        if(pj == 1) sql += ` get_live, get_live_info, get_live_pic1, get_live_pic2 ,get_live_pic3, get_live_pic4, get_live_pic5, get_live_pic6 `;
        if(pj == 2) sql += ` get_away, get_away_info, get_away_pic1, get_away_pic2, get_away_pic3, get_away_pic4, get_away_pic5, get_away_pic6 `;
        if(pj == 3) sql += ` get_line, get_line_info, get_line_pic1, get_line_pic2, get_line_pic3, get_line_pic4, get_line_pic5, get_line_pic6 `;
        if(pj == 4) sql += ` get_electric, get_electric_info, get_electric_pic1, get_electric_pic2, get_electric_pic3, get_electric_pic4, get_electric_pic5, get_electric_pic6`;
        if(pj == 5) sql += ` get_firetool, get_firetool_info, get_firetool_pic1, get_firetool_pic2, get_firetool_pic3, get_firetool_pic4, get_firetool_pic5, get_firetool_pic6`;
        if(pj == 6) sql += ` get_saveaway, get_saveaway_info, get_saveaway_pic1, get_saveaway_pic2, get_saveaway_pic3,get_saveaway_pic4, get_saveaway_pic5, get_saveaway_pic6`;
        if(pj == 7) sql += ` get_carstop, get_carstop_info, get_carstop_pic1, get_carstop_pic2, get_carstop_pic3, get_carstop_pic4, get_carstop_pic5, get_carstop_pic6`;
        if(pj == 8) sql += ` get_easyfire, get_easyfire_info, get_easyfire_pic1, get_easyfire_pic2, get_easyfire_pic3, get_easyfire_pic4, get_easyfire_pic5, get_easyfire_pic6`;
        if(pj == 9) sql += ` get_save, get_save_info, get_save_pic1, get_save_pic2, get_save_pic3, get_save_pic4, get_save_pic5, get_save_pic6`;
        if(pj == 10) sql += ` other, other_info, other_pic1, other_pic2, other_pic3, other_pic4, other_pic5, other_pic6`;

        sql += ` FROM home_base_hx where id = '${hxId}' `;
        let result = yield this._daoModel.query(sql);
        r   = result.rows
    
        return {
            code: 1,
            successed: true,
            rows: r
        }
    }

    * updateHx(req, res) {
        let r = {};
        let id = req.body.id;
        let pj = req.body.pj;
        let val = req.body.val;
        let info = req.body.info;
        let pic1 = req.body.pic1;
        let pic2 = req.body.pic2;
        let pic3 = req.body.pic3;
        let pic4 = req.body.pic4;
        let pic5 = req.body.pic5;
        let pic6 = req.body.pic6;
        let pid = req.body.pid;
        let uid = req.body.uid;
        let islast = 0;//最后一步修改
        let isReset=req.body.isReset||0; //判断是否新增还是重新设置
        //默认绿色
        let ys=3;
        if(!id)
        {
         return {
                    code: 0,
                    successed: false,
                    msg: "请传hxid"
                }
        }

        // 只要有一项不符合要求就是红色 ys=1
        if(val==1){
            let sql2 = `UPDATE home_base_hx SET violations_num = violations_num+1 WHERE id = '${id}' `;
            yield this._daoModel.query(sql2);
        }

        // 设置更新时间
        let today = date.format(new Date(), 'YYYY-MM-DD HH:mm:ss'); //当前时间
        let sql ="";

        //如果已经走完十步 重新修改不需要修改第几步   
        let hxsql = `select * from home_base_hx where  id = '${id}' `;
        let hxResult = yield this._daoModel.query(hxsql); 
        if(hxResult.rows[0].djb==10)
            sql = `UPDATE home_base_hx SET uid='${uid}', update_time = '${today}' `;
        else
            sql = `UPDATE home_base_hx SET uid='${uid}', update_time = '${today}', djb = ${pj} `;

        //修改对应项    
        if (pj == 1) {
             sql += `,get_live = '${val}' `;
             if(!info)sql += `,get_live_info = NULL `; else  sql += `,get_live_info = '${info}' `;
              if(!pic1||"")sql += `,get_live_pic1 = NULL `; else  sql += `,get_live_pic1 = '${pic1}' `; 
              if(!pic2||"")sql += `,get_live_pic2 = NULL `; else  sql += `,get_live_pic2 = '${pic2}' `; 
              if(!pic3||"")sql += `,get_live_pic3 = NULL `; else  sql += `,get_live_pic3 = '${pic3}' `; 
              if(!pic4||"")sql += `,get_live_pic4 = NULL `; else  sql += `,get_live_pic4 = '${pic4}' `; 
              if(!pic5||"")sql += `,get_live_pic5 = NULL `; else  sql += `,get_live_pic5 = '${pic5}' `; 
              if(!pic6||"")sql += `,get_live_pic6 = NULL `; else  sql += `,get_live_pic6 = '${pic6}' `; 
             sql += ` WHERE id = '${id}'`;
        	   yield this._daoModel.query(sql);

		  //在此处开始根据违规  判断颜色
            let sqlwgx = `SELECT * FROM home_base_hx WHERE id = '${id}' `;
            let wgxall = yield this._daoModel.query(sqlwgx);
            //标记第几项违规
            let wgx="不符合规范:第"     
            // 如果不涉及(2)就不能统计 只统计0 1的
            let i=0
            if(wgxall.rows[0].get_live!=2){
                i += wgxall.rows[0].get_live          //1
                if(wgxall.rows[0].get_live==1)   wgx+="1项"    
            }   
            if(wgxall.rows[0].get_away!=2){
                i += wgxall.rows[0].get_away          //2 
                if(wgxall.rows[0].get_away==1)   wgx+=" 2项" 
            }
            if(wgxall.rows[0].get_line!=2){
                i += wgxall.rows[0].get_line          //3
                if(wgxall.rows[0].get_line==1)   wgx+=" 3项" 
            }
            if(wgxall.rows[0].get_electric!=2){
                i += wgxall.rows[0].get_electric      //4
                if(wgxall.rows[0].get_electric==1)   wgx+=" 4项" 
            }
            if(wgxall.rows[0].get_firetool!=2){
                i += wgxall.rows[0].get_firetool      //5
                if(wgxall.rows[0].get_firetool==1)   wgx+=" 5项"   
            }
            if(wgxall.rows[0].get_saveaway!=2){
                i += wgxall.rows[0].get_saveaway      //6    
                if(wgxall.rows[0].get_saveaway==1)   wgx+=" 6项"   
            }
            if(wgxall.rows[0].get_carstop!=2){
                i += wgxall.rows[0].get_carstop       //7
                if(wgxall.rows[0].get_carstop==1)   wgx+=" 7项"   
            }
            if(wgxall.rows[0].get_easyfire!=2){
                i += wgxall.rows[0].get_easyfire      //8
                if(wgxall.rows[0].get_easyfire==1)   wgx+=" 8项"   
            }
            if(wgxall.rows[0].get_save!=2){
                i += wgxall.rows[0].get_save          //9
                if(wgxall.rows[0].get_save==1)   wgx+=" 9项"   
            }
            if(wgxall.rows[0].other!=2){
                i += wgxall.rows[0].other             //10
                if(wgxall.rows[0].other==1)   wgx+=" 10项"   
            } 
		  //根据违规项目判断颜色
            if(i == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范'  WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }else if(i >= 3 || wgxall.rows[0].get_live == 1){
                let sql2 = `UPDATE home_base_hx SET ys = 1, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }else if(i > 0 && i < 3 && wgxall.rows[0].get_live == 0){
                let sql2 = `UPDATE home_base_hx SET ys = 2, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }
 

        } else if (pj == 2) {
            sql += ` ,get_away = '${val}'`
            if(!info)sql += `,get_away_info = NULL `; else  sql += `, get_away_info = '${info}' `;
             if(!pic1||"")sql += `,get_away_pic1 = NULL `; sql += `,get_away_pic1 = '${pic1}' `; 
             if(!pic2||"")sql += `,get_away_pic2 = NULL `; sql += `,get_away_pic2 = '${pic2}' `; 
             if(!pic3||"")sql += `,get_away_pic3 = NULL `; sql += `,get_away_pic3 = '${pic3}' `; 
             if(!pic4||"")sql += `,get_away_pic4 = NULL `; sql += `,get_away_pic4 = '${pic4}' `; 
             if(!pic5||"")sql += `,get_away_pic5 = NULL `; sql += `,get_away_pic5 = '${pic5}' `; 
             if(!pic6||"")sql += `,get_away_pic6 = NULL `; sql += `,get_away_pic6 = '${pic6}' `; 
             sql += ` WHERE id = '${id}'`;
        	   yield this._daoModel.query(sql);
        	   
             		  //在此处开始根据违规  判断颜色
            let sqlwgx = `SELECT * FROM home_base_hx WHERE id = '${id}' `;
            let wgxall = yield this._daoModel.query(sqlwgx);
            //标记第几项违规
            let wgx="不符合规范:第"     
            // 如果不涉及(2)就不能统计 只统计0 1的
            let i=0
            if(wgxall.rows[0].get_live!=2){
                i += wgxall.rows[0].get_live          //1
                if(wgxall.rows[0].get_live==1)   wgx+="1项"    
            }   
            if(wgxall.rows[0].get_away!=2){
                i += wgxall.rows[0].get_away          //2 
                if(wgxall.rows[0].get_away==1)   wgx+=" 2项" 
            }
            if(wgxall.rows[0].get_line!=2){
                i += wgxall.rows[0].get_line          //3
                if(wgxall.rows[0].get_line==1)   wgx+=" 3项" 
            }
            if(wgxall.rows[0].get_electric!=2){
                i += wgxall.rows[0].get_electric      //4
                if(wgxall.rows[0].get_electric==1)   wgx+=" 4项" 
            }
            if(wgxall.rows[0].get_firetool!=2){
                i += wgxall.rows[0].get_firetool      //5
                if(wgxall.rows[0].get_firetool==1)   wgx+=" 5项"   
            }
            if(wgxall.rows[0].get_saveaway!=2){
                i += wgxall.rows[0].get_saveaway      //6    
                if(wgxall.rows[0].get_saveaway==1)   wgx+=" 6项"   
            }
            if(wgxall.rows[0].get_carstop!=2){
                i += wgxall.rows[0].get_carstop       //7
                if(wgxall.rows[0].get_carstop==1)   wgx+=" 7项"   
            }
            if(wgxall.rows[0].get_easyfire!=2){
                i += wgxall.rows[0].get_easyfire      //8
                if(wgxall.rows[0].get_easyfire==1)   wgx+=" 8项"   
            }
            if(wgxall.rows[0].get_save!=2){
                i += wgxall.rows[0].get_save          //9
                if(wgxall.rows[0].get_save==1)   wgx+=" 9项"   
            }
            if(wgxall.rows[0].other!=2){
                i += wgxall.rows[0].other             //10
                if(wgxall.rows[0].other==1)   wgx+=" 10项"   
            } 
		  //根据违规项目判断颜色
            if(i == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范'  WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }else if(i >= 3 || wgxall.rows[0].get_live == 1){
                let sql2 = `UPDATE home_base_hx SET ys = 1, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }else if(i > 0 && i < 3 && wgxall.rows[0].get_live == 0){
                let sql2 = `UPDATE home_base_hx SET ys = 2, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }

        } else if (pj == 3) {
            sql += ` ,get_line = '${val}'`
            if(!info)sql += `,get_line_info = NULL `; else  sql += `, get_line_info = '${info}' `;
             if(!pic1||"")sql += `,get_line_pic1 = NULL `; sql += `,get_line_pic1 = '${pic1}' `; 
             if(!pic2||"")sql += `,get_line_pic2 = NULL `; sql += `,get_line_pic2 = '${pic2}' `; 
             if(!pic3||"")sql += `,get_line_pic3 = NULL `; sql += `,get_line_pic3 = '${pic3}' `; 
             if(!pic4||"")sql += `,get_line_pic4 = NULL `; sql += `,get_line_pic4 = '${pic4}' `; 
             if(!pic5||"")sql += `,get_line_pic5 = NULL `; sql += `,get_line_pic5 = '${pic5}' `; 
             if(!pic6||"")sql += `,get_line_pic6 = NULL `; sql += `,get_line_pic6 = '${pic6}' `; 
             sql += ` WHERE id = '${id}'`;
        	   yield this._daoModel.query(sql);
        	   
             		  //在此处开始根据违规  判断颜色
            let sqlwgx = `SELECT * FROM home_base_hx WHERE id = '${id}' `;
            let wgxall = yield this._daoModel.query(sqlwgx);
            //标记第几项违规
            let wgx="不符合规范:第"     
            // 如果不涉及(2)就不能统计 只统计0 1的
            let i=0
            if(wgxall.rows[0].get_live!=2){
                i += wgxall.rows[0].get_live          //1
                if(wgxall.rows[0].get_live==1)   wgx+="1项"    
            }   
            if(wgxall.rows[0].get_away!=2){
                i += wgxall.rows[0].get_away          //2 
                if(wgxall.rows[0].get_away==1)   wgx+=" 2项" 
            }
            if(wgxall.rows[0].get_line!=2){
                i += wgxall.rows[0].get_line          //3
                if(wgxall.rows[0].get_line==1)   wgx+=" 3项" 
            }
            if(wgxall.rows[0].get_electric!=2){
                i += wgxall.rows[0].get_electric      //4
                if(wgxall.rows[0].get_electric==1)   wgx+=" 4项" 
            }
            if(wgxall.rows[0].get_firetool!=2){
                i += wgxall.rows[0].get_firetool      //5
                if(wgxall.rows[0].get_firetool==1)   wgx+=" 5项"   
            }
            if(wgxall.rows[0].get_saveaway!=2){
                i += wgxall.rows[0].get_saveaway      //6    
                if(wgxall.rows[0].get_saveaway==1)   wgx+=" 6项"   
            }
            if(wgxall.rows[0].get_carstop!=2){
                i += wgxall.rows[0].get_carstop       //7
                if(wgxall.rows[0].get_carstop==1)   wgx+=" 7项"   
            }
            if(wgxall.rows[0].get_easyfire!=2){
                i += wgxall.rows[0].get_easyfire      //8
                if(wgxall.rows[0].get_easyfire==1)   wgx+=" 8项"   
            }
            if(wgxall.rows[0].get_save!=2){
                i += wgxall.rows[0].get_save          //9
                if(wgxall.rows[0].get_save==1)   wgx+=" 9项"   
            }
            if(wgxall.rows[0].other!=2){
                i += wgxall.rows[0].other             //10
                if(wgxall.rows[0].other==1)   wgx+=" 10项"   
            } 
		  //根据违规项目判断颜色
            if(i == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范'  WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }else if(i >= 3 || wgxall.rows[0].get_live == 1){
                let sql2 = `UPDATE home_base_hx SET ys = 1, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }else if(i > 0 && i < 3 && wgxall.rows[0].get_live == 0){
                let sql2 = `UPDATE home_base_hx SET ys = 2, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }

        } else if (pj == 4) {
            sql += ` ,get_electric = '${val}'`
            if(!info)sql += `,get_electric_info = NULL `; else  sql += `, get_electric_info = '${info}' `;
             if(!pic1||"")sql += `,get_electric_pic1 = NULL `; sql += `,get_electric_pic1 = '${pic1}' `; 
             if(!pic2||"")sql += `,get_electric_pic2 = NULL `; sql += `,get_electric_pic2 = '${pic2}' `; 
             if(!pic3||"")sql += `,get_electric_pic3 = NULL `; sql += `,get_electric_pic3 = '${pic3}' `; 
             if(!pic4||"")sql += `,get_electric_pic4 = NULL `; sql += `,get_electric_pic4 = '${pic4}' `; 
             if(!pic5||"")sql += `,get_electric_pic5 = NULL `; sql += `,get_electric_pic5 = '${pic5}' `; 
             if(!pic6||"")sql += `,get_electric_pic6 = NULL `; sql += `,get_electric_pic6 = '${pic6}' `; 
             sql += ` WHERE id = '${id}'`;
        	   yield this._daoModel.query(sql);
        	   
             		  //在此处开始根据违规  判断颜色
            let sqlwgx = `SELECT * FROM home_base_hx WHERE id = '${id}' `;
            let wgxall = yield this._daoModel.query(sqlwgx);
            //标记第几项违规
            let wgx="不符合规范:第"     
            // 如果不涉及(2)就不能统计 只统计0 1的
            let i=0
            if(wgxall.rows[0].get_live!=2){
                i += wgxall.rows[0].get_live          //1
                if(wgxall.rows[0].get_live==1)   wgx+="1项"    
            }   
            if(wgxall.rows[0].get_away!=2){
                i += wgxall.rows[0].get_away          //2 
                if(wgxall.rows[0].get_away==1)   wgx+=" 2项" 
            }
            if(wgxall.rows[0].get_line!=2){
                i += wgxall.rows[0].get_line          //3
                if(wgxall.rows[0].get_line==1)   wgx+=" 3项" 
            }
            if(wgxall.rows[0].get_electric!=2){
                i += wgxall.rows[0].get_electric      //4
                if(wgxall.rows[0].get_electric==1)   wgx+=" 4项" 
            }
            if(wgxall.rows[0].get_firetool!=2){
                i += wgxall.rows[0].get_firetool      //5
                if(wgxall.rows[0].get_firetool==1)   wgx+=" 5项"   
            }
            if(wgxall.rows[0].get_saveaway!=2){
                i += wgxall.rows[0].get_saveaway      //6    
                if(wgxall.rows[0].get_saveaway==1)   wgx+=" 6项"   
            }
            if(wgxall.rows[0].get_carstop!=2){
                i += wgxall.rows[0].get_carstop       //7
                if(wgxall.rows[0].get_carstop==1)   wgx+=" 7项"   
            }
            if(wgxall.rows[0].get_easyfire!=2){
                i += wgxall.rows[0].get_easyfire      //8
                if(wgxall.rows[0].get_easyfire==1)   wgx+=" 8项"   
            }
            if(wgxall.rows[0].get_save!=2){
                i += wgxall.rows[0].get_save          //9
                if(wgxall.rows[0].get_save==1)   wgx+=" 9项"   
            }
            if(wgxall.rows[0].other!=2){
                i += wgxall.rows[0].other             //10
                if(wgxall.rows[0].other==1)   wgx+=" 10项"   
            } 
		  //根据违规项目判断颜色
            if(i == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范'  WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }else if(i >= 3 || wgxall.rows[0].get_live == 1){
                let sql2 = `UPDATE home_base_hx SET ys = 1, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }else if(i > 0 && i < 3 && wgxall.rows[0].get_live == 0){
                let sql2 = `UPDATE home_base_hx SET ys = 2, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }

        } else if (pj == 5) {
            sql += ` ,get_firetool = '${val}'`
            if(!info)sql += `,get_firetool_info = NULL `; else  sql += `, get_firetool_info = '${info}' `;
             if(!pic1||"")sql += `,get_firetool_pic1 = NULL `; sql += `,get_firetool_pic1 = '${pic1}' `;
             if(!pic2||"")sql += `,get_firetool_pic2 = NULL `; sql += `,get_firetool_pic2 = '${pic2}' `;
             if(!pic3||"")sql += `,get_firetool_pic3 = NULL `; sql += `,get_firetool_pic3 = '${pic3}' `;
             if(!pic4||"")sql += `,get_firetool_pic4 = NULL `; sql += `,get_firetool_pic4 = '${pic4}' `;
             if(!pic5||"")sql += `,get_firetool_pic5 = NULL `; sql += `,get_firetool_pic5 = '${pic5}' `;
             if(!pic6||"")sql += `,get_firetool_pic6 = NULL `; sql += `,get_firetool_pic6 = '${pic6}' `;
             sql += ` WHERE id = '${id}'`;
        	   yield this._daoModel.query(sql);
        	   
             		  //在此处开始根据违规  判断颜色
            let sqlwgx = `SELECT * FROM home_base_hx WHERE id = '${id}' `;
            let wgxall = yield this._daoModel.query(sqlwgx);
            //标记第几项违规
            let wgx="不符合规范:第"     
            // 如果不涉及(2)就不能统计 只统计0 1的
            let i=0
            if(wgxall.rows[0].get_live!=2){
                i += wgxall.rows[0].get_live          //1
                if(wgxall.rows[0].get_live==1)   wgx+="1项"    
            }   
            if(wgxall.rows[0].get_away!=2){
                i += wgxall.rows[0].get_away          //2 
                if(wgxall.rows[0].get_away==1)   wgx+=" 2项" 
            }
            if(wgxall.rows[0].get_line!=2){
                i += wgxall.rows[0].get_line          //3
                if(wgxall.rows[0].get_line==1)   wgx+=" 3项" 
            }
            if(wgxall.rows[0].get_electric!=2){
                i += wgxall.rows[0].get_electric      //4
                if(wgxall.rows[0].get_electric==1)   wgx+=" 4项" 
            }
            if(wgxall.rows[0].get_firetool!=2){
                i += wgxall.rows[0].get_firetool      //5
                if(wgxall.rows[0].get_firetool==1)   wgx+=" 5项"   
            }
            if(wgxall.rows[0].get_saveaway!=2){
                i += wgxall.rows[0].get_saveaway      //6    
                if(wgxall.rows[0].get_saveaway==1)   wgx+=" 6项"   
            }
            if(wgxall.rows[0].get_carstop!=2){
                i += wgxall.rows[0].get_carstop       //7
                if(wgxall.rows[0].get_carstop==1)   wgx+=" 7项"   
            }
            if(wgxall.rows[0].get_easyfire!=2){
                i += wgxall.rows[0].get_easyfire      //8
                if(wgxall.rows[0].get_easyfire==1)   wgx+=" 8项"   
            }
            if(wgxall.rows[0].get_save!=2){
                i += wgxall.rows[0].get_save          //9
                if(wgxall.rows[0].get_save==1)   wgx+=" 9项"   
            }
            if(wgxall.rows[0].other!=2){
                i += wgxall.rows[0].other             //10
                if(wgxall.rows[0].other==1)   wgx+=" 10项"   
            } 
		  //根据违规项目判断颜色
            if(i == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范'  WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }else if(i >= 3 || wgxall.rows[0].get_live == 1){
                let sql2 = `UPDATE home_base_hx SET ys = 1, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }else if(i > 0 && i < 3 && wgxall.rows[0].get_live == 0){
                let sql2 = `UPDATE home_base_hx SET ys = 2, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }

        } else if (pj == 6) {;
            sql += ` ,get_saveaway = '${val}'`
            if(!info)sql += `,get_saveaway_info = NULL `; else  sql += `,get_saveaway_info = '${info}' `;
             sql += `,get_saveaway_pic1 = '${pic1}' `; 
             sql += `,get_saveaway_pic2 = '${pic2}' `; 
             sql += `,get_saveaway_pic3 = '${pic3}' `; 
             sql += `,get_saveaway_pic4 = '${pic4}' `; 
             sql += `,get_saveaway_pic5 = '${pic5}' `; 
             sql += `,get_saveaway_pic6 = '${pic6}' `; 
             sql += ` WHERE id = '${id}'`;
        	   yield this._daoModel.query(sql);
        	   
             		  //在此处开始根据违规  判断颜色
            let sqlwgx = `SELECT * FROM home_base_hx WHERE id = '${id}' `;
            let wgxall = yield this._daoModel.query(sqlwgx);
            //标记第几项违规
            let wgx="不符合规范:第"     
            // 如果不涉及(2)就不能统计 只统计0 1的
            let i=0
            if(wgxall.rows[0].get_live!=2){
                i += wgxall.rows[0].get_live          //1
                if(wgxall.rows[0].get_live==1)   wgx+="1项"    
            }   
            if(wgxall.rows[0].get_away!=2){
                i += wgxall.rows[0].get_away          //2 
                if(wgxall.rows[0].get_away==1)   wgx+=" 2项" 
            }
            if(wgxall.rows[0].get_line!=2){
                i += wgxall.rows[0].get_line          //3
                if(wgxall.rows[0].get_line==1)   wgx+=" 3项" 
            }
            if(wgxall.rows[0].get_electric!=2){
                i += wgxall.rows[0].get_electric      //4
                if(wgxall.rows[0].get_electric==1)   wgx+=" 4项" 
            }
            if(wgxall.rows[0].get_firetool!=2){
                i += wgxall.rows[0].get_firetool      //5
                if(wgxall.rows[0].get_firetool==1)   wgx+=" 5项"   
            }
            if(wgxall.rows[0].get_saveaway!=2){
                i += wgxall.rows[0].get_saveaway      //6    
                if(wgxall.rows[0].get_saveaway==1)   wgx+=" 6项"   
            }
            if(wgxall.rows[0].get_carstop!=2){
                i += wgxall.rows[0].get_carstop       //7
                if(wgxall.rows[0].get_carstop==1)   wgx+=" 7项"   
            }
            if(wgxall.rows[0].get_easyfire!=2){
                i += wgxall.rows[0].get_easyfire      //8
                if(wgxall.rows[0].get_easyfire==1)   wgx+=" 8项"   
            }
            if(wgxall.rows[0].get_save!=2){
                i += wgxall.rows[0].get_save          //9
                if(wgxall.rows[0].get_save==1)   wgx+=" 9项"   
            }
            if(wgxall.rows[0].other!=2){
                i += wgxall.rows[0].other             //10
                if(wgxall.rows[0].other==1)   wgx+=" 10项"   
            } 
		  //根据违规项目判断颜色
            if(i == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范'  WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }else if(i >= 3 || wgxall.rows[0].get_live == 1){
                let sql2 = `UPDATE home_base_hx SET ys = 1, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }else if(i > 0 && i < 3 && wgxall.rows[0].get_live == 0){
                let sql2 = `UPDATE home_base_hx SET ys = 2, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }

        } else if (pj == 7) {
            sql += ` ,get_carstop = '${val}'`;
            if(!info)sql += `,get_carstop_info = NULL `; else sql += ` , get_carstop_info = '${info}' `;
             sql += `,get_carstop_pic1 = '${pic1}' `; 
             sql += `,get_carstop_pic2 = '${pic2}' `; 
             sql += `,get_carstop_pic3 = '${pic3}' `; 
             sql += `,get_carstop_pic4 = '${pic4}' `; 
             sql += `,get_carstop_pic5 = '${pic5}' `; 
             sql += `,get_carstop_pic6 = '${pic6}' `; 
             sql += ` WHERE id = '${id}'`;
        	   yield this._daoModel.query(sql);
        	   
             		  //在此处开始根据违规  判断颜色
            let sqlwgx = `SELECT * FROM home_base_hx WHERE id = '${id}' `;
            let wgxall = yield this._daoModel.query(sqlwgx);
            //标记第几项违规
            let wgx="不符合规范:第"     
            // 如果不涉及(2)就不能统计 只统计0 1的
            let i=0
            if(wgxall.rows[0].get_live!=2){
                i += wgxall.rows[0].get_live          //1
                if(wgxall.rows[0].get_live==1)   wgx+="1项"    
            }   
            if(wgxall.rows[0].get_away!=2){
                i += wgxall.rows[0].get_away          //2 
                if(wgxall.rows[0].get_away==1)   wgx+=" 2项" 
            }
            if(wgxall.rows[0].get_line!=2){
                i += wgxall.rows[0].get_line          //3
                if(wgxall.rows[0].get_line==1)   wgx+=" 3项" 
            }
            if(wgxall.rows[0].get_electric!=2){
                i += wgxall.rows[0].get_electric      //4
                if(wgxall.rows[0].get_electric==1)   wgx+=" 4项" 
            }
            if(wgxall.rows[0].get_firetool!=2){
                i += wgxall.rows[0].get_firetool      //5
                if(wgxall.rows[0].get_firetool==1)   wgx+=" 5项"   
            }
            if(wgxall.rows[0].get_saveaway!=2){
                i += wgxall.rows[0].get_saveaway      //6    
                if(wgxall.rows[0].get_saveaway==1)   wgx+=" 6项"   
            }
            if(wgxall.rows[0].get_carstop!=2){
                i += wgxall.rows[0].get_carstop       //7
                if(wgxall.rows[0].get_carstop==1)   wgx+=" 7项"   
            }
            if(wgxall.rows[0].get_easyfire!=2){
                i += wgxall.rows[0].get_easyfire      //8
                if(wgxall.rows[0].get_easyfire==1)   wgx+=" 8项"   
            }
            if(wgxall.rows[0].get_save!=2){
                i += wgxall.rows[0].get_save          //9
                if(wgxall.rows[0].get_save==1)   wgx+=" 9项"   
            }
            if(wgxall.rows[0].other!=2){
                i += wgxall.rows[0].other             //10
                if(wgxall.rows[0].other==1)   wgx+=" 10项"   
            } 
		  //根据违规项目判断颜色
            if(i == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范'  WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }else if(i >= 3 || wgxall.rows[0].get_live == 1){
                let sql2 = `UPDATE home_base_hx SET ys = 1, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }else if(i > 0 && i < 3 && wgxall.rows[0].get_live == 0){
                let sql2 = `UPDATE home_base_hx SET ys = 2, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }

        } else if (pj == 8) {
            sql += ` ,get_easyfire = '${val}'`
            if(!info)sql += `,get_easyfire_info = NULL `; else sql += `, get_easyfire_info = '${info}' `;
             sql += `,get_easyfire_pic1 = '${pic1}' `; 
             sql += `,get_easyfire_pic2 = '${pic2}' `; 
             sql += `,get_easyfire_pic3 = '${pic3}' `; 
             sql += `,get_easyfire_pic4 = '${pic4}' `; 
             sql += `,get_easyfire_pic5 = '${pic5}' `; 
             sql += `,get_easyfire_pic6 = '${pic6}' `;
             sql += ` WHERE id = '${id}'`;
        	   yield this._daoModel.query(sql);

             		  //在此处开始根据违规  判断颜色
            let sqlwgx = `SELECT * FROM home_base_hx WHERE id = '${id}' `;
            let wgxall = yield this._daoModel.query(sqlwgx);
            //标记第几项违规
            let wgx="不符合规范:第"     
            // 如果不涉及(2)就不能统计 只统计0 1的
            let i=0
            if(wgxall.rows[0].get_live!=2){
                i += wgxall.rows[0].get_live          //1
                if(wgxall.rows[0].get_live==1)   wgx+="1项"    
            }   
            if(wgxall.rows[0].get_away!=2){
                i += wgxall.rows[0].get_away          //2 
                if(wgxall.rows[0].get_away==1)   wgx+=" 2项" 
            }
            if(wgxall.rows[0].get_line!=2){
                i += wgxall.rows[0].get_line          //3
                if(wgxall.rows[0].get_line==1)   wgx+=" 3项" 
            }
            if(wgxall.rows[0].get_electric!=2){
                i += wgxall.rows[0].get_electric      //4
                if(wgxall.rows[0].get_electric==1)   wgx+=" 4项" 
            }
            if(wgxall.rows[0].get_firetool!=2){
                i += wgxall.rows[0].get_firetool      //5
                if(wgxall.rows[0].get_firetool==1)   wgx+=" 5项"   
            }
            if(wgxall.rows[0].get_saveaway!=2){
                i += wgxall.rows[0].get_saveaway      //6    
                if(wgxall.rows[0].get_saveaway==1)   wgx+=" 6项"   
            }
            if(wgxall.rows[0].get_carstop!=2){
                i += wgxall.rows[0].get_carstop       //7
                if(wgxall.rows[0].get_carstop==1)   wgx+=" 7项"   
            }
            if(wgxall.rows[0].get_easyfire!=2){
                i += wgxall.rows[0].get_easyfire      //8
                if(wgxall.rows[0].get_easyfire==1)   wgx+=" 8项"   
            }
            if(wgxall.rows[0].get_save!=2){
                i += wgxall.rows[0].get_save          //9
                if(wgxall.rows[0].get_save==1)   wgx+=" 9项"   
            }
            if(wgxall.rows[0].other!=2){
                i += wgxall.rows[0].other             //10
                if(wgxall.rows[0].other==1)   wgx+=" 10项"   
            } 
		  //根据违规项目判断颜色
            if(i == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范'  WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }else if(i >= 3 || wgxall.rows[0].get_live == 1){
                let sql2 = `UPDATE home_base_hx SET ys = 1, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }else if(i > 0 && i < 3 && wgxall.rows[0].get_live == 0){
                let sql2 = `UPDATE home_base_hx SET ys = 2, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }

        } else if (pj == 9) {
            sql += ` ,get_save = '${val}'`
            if(!info)sql += `,get_save_info = NULL `; else sql += `, get_save_info = '${info}' `;
             sql += `,get_save_pic1 = '${pic1}' `; 
             sql += `,get_save_pic2 = '${pic2}' `; 
             sql += `,get_save_pic3 = '${pic3}' `; 
             sql += `,get_save_pic4 = '${pic4}' `; 
             sql += `,get_save_pic5 = '${pic5}' `; 
             sql += `,get_save_pic6 = '${pic6}' `; 
             sql += ` WHERE id = '${id}'`;
        	   yield this._daoModel.query(sql);

             		  //在此处开始根据违规  判断颜色
            let sqlwgx = `SELECT * FROM home_base_hx WHERE id = '${id}' `;
            let wgxall = yield this._daoModel.query(sqlwgx);
            //标记第几项违规
            let wgx="不符合规范:第"     
            // 如果不涉及(2)就不能统计 只统计0 1的
            let i=0
            if(wgxall.rows[0].get_live!=2){
                i += wgxall.rows[0].get_live          //1
                if(wgxall.rows[0].get_live==1)   wgx+="1项"    
            }   
            if(wgxall.rows[0].get_away!=2){
                i += wgxall.rows[0].get_away          //2 
                if(wgxall.rows[0].get_away==1)   wgx+=" 2项" 
            }
            if(wgxall.rows[0].get_line!=2){
                i += wgxall.rows[0].get_line          //3
                if(wgxall.rows[0].get_line==1)   wgx+=" 3项" 
            }
            if(wgxall.rows[0].get_electric!=2){
                i += wgxall.rows[0].get_electric      //4
                if(wgxall.rows[0].get_electric==1)   wgx+=" 4项" 
            }
            if(wgxall.rows[0].get_firetool!=2){
                i += wgxall.rows[0].get_firetool      //5
                if(wgxall.rows[0].get_firetool==1)   wgx+=" 5项"   
            }
            if(wgxall.rows[0].get_saveaway!=2){
                i += wgxall.rows[0].get_saveaway      //6    
                if(wgxall.rows[0].get_saveaway==1)   wgx+=" 6项"   
            }
            if(wgxall.rows[0].get_carstop!=2){
                i += wgxall.rows[0].get_carstop       //7
                if(wgxall.rows[0].get_carstop==1)   wgx+=" 7项"   
            }
            if(wgxall.rows[0].get_easyfire!=2){
                i += wgxall.rows[0].get_easyfire      //8
                if(wgxall.rows[0].get_easyfire==1)   wgx+=" 8项"   
            }
            if(wgxall.rows[0].get_save!=2){
                i += wgxall.rows[0].get_save          //9
                if(wgxall.rows[0].get_save==1)   wgx+=" 9项"   
            }
            if(wgxall.rows[0].other!=2){
                i += wgxall.rows[0].other             //10
                if(wgxall.rows[0].other==1)   wgx+=" 10项"   
            } 
		  //根据违规项目判断颜色
            if(i == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范'  WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }else if(i >= 3 || wgxall.rows[0].get_live == 1){
                let sql2 = `UPDATE home_base_hx SET ys = 1, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }else if(i > 0 && i < 3 && wgxall.rows[0].get_live == 0){
                let sql2 = `UPDATE home_base_hx SET ys = 2, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }

        }  else  {
            islast = 1;//最后一步修改
            sql += ` ,other = '${val}'`;
            if(!info)sql += `,other_info = NULL `; else sql += `, other_info = '${info}' `;
             sql += `,other_pic1 = '${pic1}' `; 
             sql += `,other_pic2 = '${pic2}' `; 
             sql += `,other_pic3 = '${pic3}' `; 
             sql += `,other_pic4 = '${pic4}' `; 
             sql += `,other_pic5 = '${pic5}' `; 
             sql += `,other_pic6 = '${pic6}' `;
             sql += ` WHERE id = '${id}'`;
        	   yield this._daoModel.query(sql);


             		  //在此处开始根据违规  判断颜色
            let sqlwgx = `SELECT * FROM home_base_hx WHERE id = '${id}' `;
            let wgxall = yield this._daoModel.query(sqlwgx);
            //标记第几项违规
            let wgx="不符合规范:第"     
            // 如果不涉及(2)就不能统计 只统计0 1的
            let i=0
            if(wgxall.rows[0].get_live!=2){
                i += wgxall.rows[0].get_live          //1
                if(wgxall.rows[0].get_live==1)   wgx+="1项"    
            }   
            if(wgxall.rows[0].get_away!=2){
                i += wgxall.rows[0].get_away          //2 
                if(wgxall.rows[0].get_away==1)   wgx+=" 2项" 
            }
            if(wgxall.rows[0].get_line!=2){
                i += wgxall.rows[0].get_line          //3
                if(wgxall.rows[0].get_line==1)   wgx+=" 3项" 
            }
            if(wgxall.rows[0].get_electric!=2){
                i += wgxall.rows[0].get_electric      //4
                if(wgxall.rows[0].get_electric==1)   wgx+=" 4项" 
            }
            if(wgxall.rows[0].get_firetool!=2){
                i += wgxall.rows[0].get_firetool      //5
                if(wgxall.rows[0].get_firetool==1)   wgx+=" 5项"   
            }
            if(wgxall.rows[0].get_saveaway!=2){
                i += wgxall.rows[0].get_saveaway      //6    
                if(wgxall.rows[0].get_saveaway==1)   wgx+=" 6项"   
            }
            if(wgxall.rows[0].get_carstop!=2){
                i += wgxall.rows[0].get_carstop       //7
                if(wgxall.rows[0].get_carstop==1)   wgx+=" 7项"   
            }
            if(wgxall.rows[0].get_easyfire!=2){
                i += wgxall.rows[0].get_easyfire      //8
                if(wgxall.rows[0].get_easyfire==1)   wgx+=" 8项"   
            }
            if(wgxall.rows[0].get_save!=2){
                i += wgxall.rows[0].get_save          //9
                if(wgxall.rows[0].get_save==1)   wgx+=" 9项"   
            }
            if(wgxall.rows[0].other!=2){
                i += wgxall.rows[0].other             //10
                if(wgxall.rows[0].other==1)   wgx+=" 10项"   
            } 
		  //根据违规项目判断颜色
            if(i == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范'  WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }else if(i >= 3 || wgxall.rows[0].get_live == 1){
                let sql2 = `UPDATE home_base_hx SET ys = 1, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }else if(i > 0 && i < 3 && wgxall.rows[0].get_live == 0){
                let sql2 = `UPDATE home_base_hx SET ys = 2, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }
            
        } 


//        //最后一步才会执行
//        if(islast == 1) { 
//            let sqlwgx = `SELECT * FROM home_base_hx WHERE id = '${id}' `;
//            let wgxall = yield this._daoModel.query(sqlwgx);
//
//            //标记第几项违规
//            let wgx="不符合规范:第"     
//            // 如果不涉及(2)就不能统计 只统计0 1的
//            let i=0
//            if(wgxall.rows[0].get_live!=2){
//                i += wgxall.rows[0].get_live          //1
//                if(wgxall.rows[0].get_live==1)   wgx+="1项"                               
//                
//            }   
//            if(wgxall.rows[0].get_away!=2){
//                i += wgxall.rows[0].get_away          //2 
//                if(wgxall.rows[0].get_away==1)   wgx+=" 2项" 
//            }
//           
//            if(wgxall.rows[0].get_line!=2){
//                i += wgxall.rows[0].get_line          //3
//                if(wgxall.rows[0].get_line==1)   wgx+=" 3项" 
//            }
//
//            if(wgxall.rows[0].get_electric!=2){
//                i += wgxall.rows[0].get_electric      //4
//                if(wgxall.rows[0].get_electric==1)   wgx+=" 4项" 
//            }
//
//            if(wgxall.rows[0].get_firetool!=2){
//                i += wgxall.rows[0].get_firetool      //5
//                if(wgxall.rows[0].get_firetool==1)   wgx+=" 5项"   
//            }
//
//            if(wgxall.rows[0].get_saveaway!=2){
//                i += wgxall.rows[0].get_saveaway      //6    
//                if(wgxall.rows[0].get_saveaway==1)   wgx+=" 6项"   
//            }
//           
//            if(wgxall.rows[0].get_carstop!=2){
//                i += wgxall.rows[0].get_carstop       //7
//                if(wgxall.rows[0].get_carstop==1)   wgx+=" 7项"   
//            }
//
//            if(wgxall.rows[0].get_easyfire!=2){
//                i += wgxall.rows[0].get_easyfire      //8
//                if(wgxall.rows[0].get_easyfire==1)   wgx+=" 8项"   
//            }
//  
//            if(wgxall.rows[0].get_save!=2){
//                i += wgxall.rows[0].get_save          //9
//                if(wgxall.rows[0].get_save==1)   wgx+=" 9项"   
//            }
//
//            if(wgxall.rows[0].other!=2){
//                i += wgxall.rows[0].other             //10
//                if(wgxall.rows[0].other==1)   wgx+=" 10项"   
//            }
//      
//            // 1.检查未发现隐患问题的（检查项全部为否）风险等级判定为绿色。
//            // 2.存在违规住人或者3项以上（含）隐患问题的风险等级判定为红色。
//            // 3.其余情况风险等级判定为黄色。
//            if(i == 0) {
//                let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范'  WHERE id = '${id}' `;
//                yield this._daoModel.query(sql2);
//            }else if(i >= 3 || wgxall.rows[0].get_live == 1){
//                let sql2 = `UPDATE home_base_hx SET ys = 1, note = '${wgx}'   WHERE id = '${id}' `;
//                yield this._daoModel.query(sql2);
//            }else if(i > 0 && i < 3 && wgxall.rows[0].get_live == 0){
//                let sql2 = `UPDATE home_base_hx SET ys = 2, note = '${wgx}'   WHERE id = '${id}' `;
//                yield this._daoModel.query(sql2);
//            }
//        }

        let queryByid = `select * from home_base_hx where id = '${id}'`;
        let hxByid = yield this._daoModel.query(queryByid);
        r   = hxByid.rows

        let queryHb = `select name from home_base where id = '${pid}'`;
        let resulthb = yield this._daoModel.query(queryHb);

        let hbName = resulthb.rows[0].name;
        return {
            code: 1,
            successed: true,
            rows: r,
            hbName,hbName
        }
    }


    * qrtj(req, res) {

        let id = req.body.id;
        let pid = req.body.pid;
        let r = {};
        let sqlwgx = `SELECT * FROM home_base_hx WHERE id = '${id}' `;
        let wgxall = yield this._daoModel.query(sqlwgx);
        
                    //标记第几项违规
                    let wgx="不符合规范:第"     
                    // 如果不涉及(2)就不能统计 只统计0 1的
                    let i=0
                    if(wgxall.rows[0].get_live!=2){
                        i += wgxall.rows[0].get_live          //1
                        if(wgxall.rows[0].get_live==1)   wgx+="1项"                               
                        
                    }   
                    if(wgxall.rows[0].get_away!=2){
                        i += wgxall.rows[0].get_away          //2 
                        if(wgxall.rows[0].get_away==1)   wgx+=" 2项" 
                    }
                   
                    if(wgxall.rows[0].get_line!=2){
                        i += wgxall.rows[0].get_line          //3
                        if(wgxall.rows[0].get_line==1)   wgx+=" 3项" 
                    }
        
                    if(wgxall.rows[0].get_electric!=2){
                        i += wgxall.rows[0].get_electric      //4
                        if(wgxall.rows[0].get_electric==1)   wgx+=" 4项" 
                    }
        
                    if(wgxall.rows[0].get_firetool!=2){
                        i += wgxall.rows[0].get_firetool      //5
                        if(wgxall.rows[0].get_firetool==1)   wgx+=" 5项"   
                    }
        
                    if(wgxall.rows[0].get_saveaway!=2){
                        i += wgxall.rows[0].get_saveaway      //6    
                        if(wgxall.rows[0].get_saveaway==1)   wgx+=" 6项"   
                    }
                   
                    if(wgxall.rows[0].get_carstop!=2){
                        i += wgxall.rows[0].get_carstop       //7
                        if(wgxall.rows[0].get_carstop==1)   wgx+=" 7项"   
                    }
        
                    if(wgxall.rows[0].get_easyfire!=2){
                        i += wgxall.rows[0].get_easyfire      //8
                        if(wgxall.rows[0].get_easyfire==1)   wgx+=" 8项"   
                    }
          
                    if(wgxall.rows[0].get_save!=2){
                        i += wgxall.rows[0].get_save          //9
                        if(wgxall.rows[0].get_save==1)   wgx+=" 9项"   
                    }
        
                    if(wgxall.rows[0].other!=2){
                        i += wgxall.rows[0].other             //10
                        if(wgxall.rows[0].other==1)   wgx+=" 10项"   
                    }
              
                    // 1.检查未发现隐患问题的（检查项全部为否）风险等级判定为绿色。
                    // 2.存在违规住人或者3项以上（含）隐患问题的风险等级判定为红色。
                    // 3.其余情况风险等级判定为黄色。
                    if(i == 0) {
                        let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范'  WHERE id = '${id}' `;
                        yield this._daoModel.query(sql2);
                        //let hbSql = `UPDATE home_base SET ys = 3, note = '符合规范'  WHERE id = '${pid}'` ;
                        //yield this._daoModel.query(hbSql);
                    }else if(i >= 3 || wgxall.rows[0].get_live == 1){
                        let sql2 = `UPDATE home_base_hx SET ys = 1, note = '${wgx}'   WHERE id = '${id}' `;
                        yield this._daoModel.query(sql2);
                        //let hbSql = `UPDATE home_base SET ys = 1, note = '${wgx}'   WHERE id = '${pid}'` ;
                        //yield this._daoModel.query(hbSql);
                    }else if(i > 0 && i < 3 && wgxall.rows[0].get_live == 0){
                        let sql2 = `UPDATE home_base_hx SET ys = 2, note = '${wgx}'   WHERE id = '${id}' `;
                        yield this._daoModel.query(sql2);
                        //let hbSql = `UPDATE home_base SET ys = 2, note = '${wgx}'   WHERE id = '${pid}'` ;
                        //yield this._daoModel.query(hbSql);
                    }
                let queryByid = `select * from home_base_hx where id = '${id}'`;
                let hxByid = yield this._daoModel.query(queryByid);
                r   = hxByid.rows
        
                let queryHb = `select name from home_base where id = '${pid}'`;
                let resulthb = yield this._daoModel.query(queryHb);
        
                let hbName = resulthb.rows[0].name;
                return {
                    code: 1,
                    successed: true,
                    rows: r,
                    hbName,hbName
                }
    }

    * reUpdateHx(req, res) {
        let r = {};
        let id = req.body.id;
        let pj = req.body.pj;
        let val = req.body.val;
        let info = req.body.info;
        let pic1 = req.body.pic1;
        let pic2 = req.body.pic2;
        let pic3 = req.body.pic3;
        let pic4 = req.body.pic4;
        let pic5 = req.body.pic5;
        let pic6 = req.body.pic6;
        let pid = req.body.pid;
        let uid = req.body.uid;
        //默认绿色
        let ys=3;
        if(!id)
        {
        return {
                    code: 0,
                    successed: false,
                    msg: "请传hxid"
                }
        }

        // 只要有一项不符合要求就是黄色 ys=2
        if(val==1){
            let sql2 = `UPDATE home_base_hx SET violations_num = violations_num+1 WHERE id = '${id}' `;
            yield this._daoModel.query(sql2);
        }

        // 设置更新时间
        let today = date.format(new Date(), 'YYYY-MM-DD HH:mm:ss'); //当前时间

        let sql = `UPDATE home_base_hx SET uid='${uid}', update_time = '${today}', djb = ${pj} `;
        if (pj == 1) {
            sql += ` ,get_live = '${val}' `;
            if(info==null)sql += `,get_live_info = 'NULL' `; else sql += `,get_live_info = '${info}' `; 
            if(pic1) sql += `,get_live_pic1 = '${pic1}' `; 
            if(pic2) sql += `,get_live_pic2 = '${pic2}' `; 
            if(pic3) sql += `,get_live_pic3 = '${pic3}' `; 
            if(pic4) sql += `,get_live_pic4 = '${pic4}' `; 
            if(pic5) sql += `,get_live_pic5 = '${pic5}' `; 
            if(pic6) sql += `,get_live_pic6 = '${pic6}' `; 

        } else if (pj == 2) {
            sql += ` ,get_away = '${val}'`
            if(info==null)sql += `,get_away_info = 'NULL' `; else sql += `, get_away_info = '${info}' `;
            if(pic1) sql += `,get_away_pic1 = '${pic1}' `; 
            if(pic2) sql += `,get_away_pic2 = '${pic2}' `; 
            if(pic3) sql += `,get_away_pic3 = '${pic3}' `; 
            if(pic4) sql += `,get_away_pic4 = '${pic4}' `; 
            if(pic5) sql += `,get_away_pic5 = '${pic5}' `; 
            if(pic6) sql += `,get_away_pic6 = '${pic6}' `; 

        } else if (pj == 3) {
            sql += ` ,get_line = '${val}'`
            if(info==null)sql += `,get_line_info = 'NULL' `; else sql += `, get_line_info = '${info}' `;
            if(pic1) sql += `,get_line_pic1 = '${pic1}' `; 
            if(pic2) sql += `,get_line_pic2 = '${pic2}' `; 
            if(pic3) sql += `,get_line_pic3 = '${pic3}' `; 
            if(pic4) sql += `,get_line_pic4 = '${pic4}' `; 
            if(pic5) sql += `,get_line_pic5 = '${pic5}' `; 
            if(pic6) sql += `,get_line_pic6 = '${pic6}' `; 

        } else if (pj == 4) {
            sql += ` ,get_electric = '${val}'`
            if(info==null)sql += `,get_electric_info = 'NULL' `; else sql += `, get_electric_info = '${info}' `;
            if(pic1) sql += `,get_electric_pic1 = '${pic1}' `; 
            if(pic2) sql += `,get_electric_pic2 = '${pic2}' `; 
            if(pic3) sql += `,get_electric_pic3 = '${pic3}' `; 
            if(pic4) sql += `,get_electric_pic4 = '${pic4}' `; 
            if(pic5) sql += `,get_electric_pic5 = '${pic5}' `; 
            if(pic6) sql += `,get_electric_pic6 = '${pic6}' `; 

        } else if (pj == 5) {
            sql += ` ,get_firetool = '${val}'`
            if(info==null)sql += `,get_firetool_info = 'NULL' `; else sql += `, get_firetool_info = '${info}' `;
            if(pic1) sql += `,get_firetool_pic1 = '${pic1}' `; 
            if(pic2) sql += `,get_firetool_pic2 = '${pic2}' `; 
            if(pic3) sql += `,get_firetool_pic3 = '${pic3}' `; 
            if(pic4) sql += `,get_firetool_pic4 = '${pic4}' `; 
            if(pic5) sql += `,get_firetool_pic5 = '${pic5}' `; 
            if(pic6) sql += `,get_firetool_pic6 = '${pic6}' `; 

        } else if (pj == 6) {;
            sql += ` ,get_saveaway = '${val}'`
            if(info==null)sql += `,get_saveaway_info = 'NULL' `; else sql += `,get_saveaway_info = '${info}' `;
            if(pic1) sql += `,get_saveaway_pic1 = '${pic1}' `; 
            if(pic2) sql += `,get_saveaway_pic2 = '${pic2}' `; 
            if(pic3) sql += `,get_saveaway_pic3 = '${pic3}' `; 
            if(pic4) sql += `,get_saveaway_pic4 = '${pic4}' `; 
            if(pic5) sql += `,get_saveaway_pic5 = '${pic5}' `; 
            if(pic6) sql += `,get_saveaway_pic6 = '${pic6}' `; 
        } else if (pj == 7) {
            sql += ` ,get_carstop = '${val}'`;
            if(info==null)sql += `,get_carstop_info = 'NULL' `; else sql += ` , get_carstop_info = '${info}' `;
            if(pic1) sql += `,get_carstop_pic1 = '${pic1}' `; 
            if(pic2) sql += `,get_carstop_pic2 = '${pic2}' `; 
            if(pic3) sql += `,get_carstop_pic3 = '${pic3}' `; 
            if(pic4) sql += `,get_carstop_pic4 = '${pic4}' `; 
            if(pic5) sql += `,get_carstop_pic5 = '${pic5}' `; 
            if(pic6) sql += `,get_carstop_pic6 = '${pic6}' `; 
        } else if (pj == 8) {
            sql += ` ,get_easyfire = '${val}'`
            if(info==null)sql += `,get_easyfire_info = 'NULL' `; else sql += `, get_easyfire_info = '${info}' `;
            if(pic1) sql += `,get_easyfire_pic1 = '${pic1}' `; 
            if(pic2) sql += `,get_easyfire_pic2 = '${pic2}' `; 
            if(pic3) sql += `,get_easyfire_pic3 = '${pic3}' `; 
            if(pic4) sql += `,get_easyfire_pic4 = '${pic4}' `; 
            if(pic5) sql += `,get_easyfire_pic5 = '${pic5}' `; 
            if(pic6) sql += `,get_easyfire_pic6 = '${pic6}' `; 
        } else if (pj == 9) {
            sql += ` ,get_save = '${val}'`
            if(info==null)sql += `,get_save_info = 'NULL' `; else sql += `, get_save_info = '${info}' `;
            if(pic1) sql += `,get_save_pic1 = '${pic1}' `; 
            if(pic2) sql += `,get_save_pic2 = '${pic2}' `; 
            if(pic3) sql += `,get_save_pic3 = '${pic3}' `; 
            if(pic4) sql += `,get_save_pic4 = '${pic4}' `; 
            if(pic5) sql += `,get_save_pic5 = '${pic5}' `; 
            if(pic6) sql += `,get_save_pic6 = '${pic6}' `; 
        }  else  {
            sql += ` ,other = '${val}'`
            if(info==null)sql += `,other_info = 'NULL' `; else sql += `, other_info = '${info}' `;
            if(pic1) sql += `,other_pic1 = '${pic1}' `; 
            if(pic2) sql += `,other_pic2 = '${pic2}' `; 
            if(pic3) sql += `,other_pic3 = '${pic3}' `; 
            if(pic4) sql += `,other_pic4 = '${pic4}' `; 
            if(pic5) sql += `,other_pic5 = '${pic5}' `; 
            if(pic6) sql += `,other_pic6 = '${pic6}' `;

            //如果ys字段没有改变过 就可以认为是绿色
            let sql1 = `SELECT violations_num FROM home_base_hx WHERE id = '${id}' `;
            let hx_ys = yield this._daoModel.query(sql1);
            console.log(hx_ys.rows[0].ys);
            if(hx_ys.rows[0].violations_num == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范' WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
                let hbSql = `UPDATE home_base SET ys = 3, note = '符合规范' WHERE id = '${pid}'` ;
                yield this._daoModel.query(hbSql);
            }else if(hx_ys.rows[0].violations_num > 0){
                let sql2 = `UPDATE home_base_hx SET ys = 2, note = '不符合规范' WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
                let hbSql = `UPDATE home_base SET ys = 2, note = '不符合规范' WHERE id = '${pid}'` ;
                yield this._daoModel.query(hbSql);
            }

        } 
        sql += ` WHERE id = '${id}'`;
        let result = yield this._daoModel.query(sql);
        let queryByid = `select * from home_base_hx where id = '${id}'`;
        let hxByid = yield this._daoModel.query(queryByid);
        r   = hxByid.rows

        let queryHb = `select name from home_base where id = '${pid}'`;
        let resulthb = yield this._daoModel.query(queryHb);

        let hbName = resulthb.rows[0].name;
        return {
            code: 1,
            successed: true,
            rows: r,
            hbName:hbName
        }
    }

    // * saveShyj1(req, res) {
    //     let r = {};
    //     let id = req.body.id;
    //     let sh_note = req.body.sh_note;
    //     let zg_time = req.body.zg_time;
    //     let sql = `update home_base_hx set sh_note = '${sh_note}', zg_time = '${zg_time}' where id = '${id}'`  ;
    //     let result = yield this._daoModel.query(sql);
    //     let hxsql = `select update_time, pid from home_base_hx where id= '${id}'`;
    //     let hxdetail = yield this._daoModel.query(hxsql);
    //     let hxupdate_time = hxdetail.rows[0].update_time;
    //     let pid = hxdetail.rows[0].pid;
    //     // 为hb插入新的时间
    //     let hbsql = `update home_base set sh_time = '${hxupdate_time}', zg_time = '${zg_time}' where id = '${pid}' `;
    //     yield this._daoModel.query(hbsql);
    //     r   = result.rows;
    //     r.sh_note = sh_note;
    //     r.zg_time = req.body.zg_time;
    //     return {
    //         code: 1,
    //         successed: true,
    //         rows: r
    //     }
    // }

    * getHxById(req, res) {
        let r = {};
        let id = req.params.id;
        let sql = `SELECT * FROM home_base_hx WHERE id = ` + id;
        let result = yield this._daoModel.query(sql);
        r   = result.rows

        return {
            code: 1,
            successed: true,
            rows: r
        }
    }
    

    * getHxByPid(req, res) {
        let r = {};
        let pid = req.params.pid;
        let sql = 'SELECT * FROM home_base_hx WHERE pid = ' + pid +' order by create_time desc';
        let result = yield this._daoModel.query(sql);
        result.rows.map((item, index) => {
            if (item.get_live_pic1&&item.get_live_pic1.indexOf('http') == -1) {
                item.get_live_pic1 = config.appsetting.picHead + item.get_live_pic1;
            } 
            if (item.get_live_pic2&&item.get_live_pic2.indexOf('http') == -1) {
                item.get_live_pic2 = config.appsetting.picHead + item.get_live_pic2;
            } 
            if (item.get_live_pic3&&item.get_live_pic3.indexOf('http') == -1) {
                item.get_live_pic3 = config.appsetting.picHead + item.get_live_pic3;
            } 
            if (item.get_live_pic4&&item.get_live_pic4.indexOf('http') == -1) {
                item.get_live_pic4 = config.appsetting.picHead + item.get_live_pic4;
            } 
            if (item.get_live_pic5&&item.get_live_pic5.indexOf('http') == -1) {
                item.get_live_pic5 = config.appsetting.picHead + item.get_live_pic5;
            } 
            if (item.get_live_pic6&&item.get_live_pic6.indexOf('http') == -1) {
                item.get_live_pic6 = config.appsetting.picHead + item.get_live_pic6;
            } 

            if (item.get_away_pic1&&item.get_away_pic1.indexOf('http') == -1) {
                item.get_away_pic1 = config.appsetting.picHead + item.get_away_pic1;
            } 
            if (item.get_away_pic2&&item.get_away_pic2.indexOf('http') == -1) {
                item.get_away_pic2 = config.appsetting.picHead + item.get_away_pic2;
            } 
            if (item.get_away_pic3&&item.get_away_pic3.indexOf('http') == -1) {
                item.get_away_pic3 = config.appsetting.picHead + item.get_away_pic3;
            } 
            if (item.get_away_pic4&&item.get_away_pic4.indexOf('http') == -1) {
                item.get_away_pic4 = config.appsetting.picHead + item.get_away_pic4;
            } 
            if (item.get_away_pic5&&item.get_away_pic5.indexOf('http') == -1) {
                item.get_away_pic5 = config.appsetting.picHead + item.get_away_pic5;
            } 
            if (item.get_away_pic6&&item.get_away_pic6.indexOf('http') == -1) {
                item.get_away_pic6 = config.appsetting.picHead + item.get_away_pic6;
            } 

            if (item.get_line_pic1&&item.get_line_pic1.indexOf('http') == -1) {
                item.get_line_pic1 = config.appsetting.picHead + item.get_line_pic1;
            } 
            if (item.get_line_pic2&&item.get_line_pic2.indexOf('http') == -1) {
                item.get_line_pic2 = config.appsetting.picHead + item.get_line_pic2;
            } 
            if (item.get_line_pic3&&item.get_line_pic3.indexOf('http') == -1) {
                item.get_line_pic3 = config.appsetting.picHead + item.get_line_pic3;
            } 
            if (item.get_line_pic4&&item.get_line_pic4.indexOf('http') == -1) {
                item.get_line_pic4 = config.appsetting.picHead + item.get_line_pic4;
            } 
            if (item.get_line_pic5&&item.get_line_pic5.indexOf('http') == -1) {
                item.get_line_pic5 = config.appsetting.picHead + item.get_line_pic5;
            } 
            if (item.get_line_pic6&&item.get_line_pic6.indexOf('http') == -1) {
                item.get_line_pic6 = config.appsetting.picHead + item.get_line_pic6;
            } 


            if (item.get_electric_pic1&&item.get_electric_pic1.indexOf('http') == -1) {
                item.get_electric_pic1 = config.appsetting.picHead + item.get_electric_pic1;
            } 
            if (item.get_electric_pic2&&item.get_electric_pic2.indexOf('http') == -1) {
                item.get_electric_pic2 = config.appsetting.picHead + item.get_electric_pic2;
            } 
            if (item.get_electric_pic3&&item.get_electric_pic3.indexOf('http') == -1) {
                item.get_electric_pic3 = config.appsetting.picHead + item.get_electric_pic3;
            } 
            if (item.get_electric_pic4&&item.get_electric_pic4.indexOf('http') == -1) {
                item.get_electric_pic4 = config.appsetting.picHead + item.get_electric_pic4;
            } 
            if (item.get_electric_pic5&&item.get_electric_pic5.indexOf('http') == -1) {
                item.get_electric_pic5 = config.appsetting.picHead + item.get_electric_pic5;
            } 
            if (item.get_electric_pic6&&item.get_electric_pic6.indexOf('http') == -1) {
                item.get_electric_pic6 = config.appsetting.picHead + item.get_electric_pic6;
            } 

            if (item.get_firetool_pic1&&item.get_firetool_pic1.indexOf('http') == -1) {
                item.get_firetool_pic1 = config.appsetting.picHead + item.get_firetool_pic1;
            } 
            if (item.get_firetool_pic2&&item.get_firetool_pic2.indexOf('http') == -1) {
                item.get_firetool_pic2 = config.appsetting.picHead + item.get_firetool_pic2;
            } 
            if (item.get_firetool_pic3&&item.get_firetool_pic3.indexOf('http') == -1) {
                item.get_firetool_pic3 = config.appsetting.picHead + item.get_firetool_pic3;
            } 
            if (item.get_firetool_pic4&&item.get_firetool_pic4.indexOf('http') == -1) {
                item.get_firetool_pic4 = config.appsetting.picHead + item.get_firetool_pic4;
            } 
            if (item.get_firetool_pic5&&item.get_firetool_pic5.indexOf('http') == -1) {
                item.get_firetool_pic5 = config.appsetting.picHead + item.get_firetool_pic5;
            } 
            if (item.get_firetool_pic6&&item.get_firetool_pic6.indexOf('http') == -1) {
                item.get_firetool_pic6 = config.appsetting.picHead + item.get_firetool_pic6;
            } 

            if (item.get_saveaway_pic1&&item.get_saveaway_pic1.indexOf('http') == -1) {
                item.get_saveaway_pic1 = config.appsetting.picHead + item.get_saveaway_pic1;
            } 
            if (item.get_saveaway_pic2&&item.get_saveaway_pic2.indexOf('http') == -1) {
                item.get_saveaway_pic2 = config.appsetting.picHead + item.get_saveaway_pic2;
            } 
            if (item.get_saveaway_pic3&&item.get_saveaway_pic3.indexOf('http') == -1) {
                item.get_saveaway_pic3 = config.appsetting.picHead + item.get_saveaway_pic3;
            } 
            if (item.get_saveaway_pic4&&item.get_saveaway_pic4.indexOf('http') == -1) {
                item.get_saveaway_pic4 = config.appsetting.picHead + item.get_saveaway_pic4;
            } 
            if (item.get_saveaway_pic5&&item.get_saveaway_pic5.indexOf('http') == -1) {
                item.get_saveaway_pic5 = config.appsetting.picHead + item.get_saveaway_pic5;
            } 
            if (item.get_saveaway_pic6&&item.get_saveaway_pic6.indexOf('http') == -1) {
                item.get_saveaway_pic6 = config.appsetting.picHead + item.get_saveaway_pic6;
            } 

            if (item.get_carstop_pic1&&item.get_carstop_pic1.indexOf('http') == -1) {
                item.get_carstop_pic1 = config.appsetting.picHead + item.get_carstop_pic1;
            } 
            if (item.get_carstop_pic2&&item.get_carstop_pic2.indexOf('http') == -1) {
                item.get_carstop_pic2 = config.appsetting.picHead + item.get_carstop_pic2;
            } 

            if (item.get_carstop_pic3&&item.get_carstop_pic3.indexOf('http') == -1) {
                item.get_carstop_pic3 = config.appsetting.picHead + item.get_carstop_pic3;
            } 

            if (item.get_carstop_pic4&&item.get_carstop_pic4.indexOf('http') == -1) {
                item.get_carstop_pic4 = config.appsetting.picHead + item.get_carstop_pic4;
            } 

            if (item.get_carstop_pic5&&item.get_carstop_pic5.indexOf('http') == -1) {
                item.get_carstop_pic5 = config.appsetting.picHead + item.get_carstop_pic5;
            } 
            if (item.get_carstop_pic6&&item.get_carstop_pic6.indexOf('http') == -1) {
                item.get_carstop_pic6 = config.appsetting.picHead + item.get_carstop_pic6;
            } 


            if (item.get_easyfire_pic1&&item.get_easyfire_pic1.indexOf('http') == -1) {
                item.get_easyfire_pic1 = config.appsetting.picHead + item.get_easyfire_pic1;
            } 
            if (item.get_easyfire_pic2&&item.get_easyfire_pic2.indexOf('http') == -1) {
                item.get_easyfire_pic2 = config.appsetting.picHead + item.get_easyfire_pic2;
            } 
            if (item.get_easyfire_pic3&&item.get_easyfire_pic3.indexOf('http') == -1) {
                item.get_easyfire_pic3 = config.appsetting.picHead + item.get_easyfire_pic3;
            } 
            if (item.get_easyfire_pic4&&item.get_easyfire_pic4.indexOf('http') == -1) {
                item.get_easyfire_pic4 = config.appsetting.picHead + item.get_easyfire_pic4;
            } 
            if (item.get_easyfire_pic5&&item.get_easyfire_pic5.indexOf('http') == -1) {
                item.get_easyfire_pic5 = config.appsetting.picHead + item.get_easyfire_pic5;
            } 
            if (item.get_easyfire_pic6&&item.get_easyfire_pic6.indexOf('http') == -1) {
                item.get_easyfire_pic6 = config.appsetting.picHead + item.get_easyfire_pic6;
            } 

            if (item.get_save_pic1&&item.get_save_pic1.indexOf('http') == -1) {
                item.get_save_pic1 = config.appsetting.picHead + item.get_save_pic1;
            } 
            if (item.get_save_pic2&&item.get_save_pic2.indexOf('http') == -1) {
                item.get_save_pic2 = config.appsetting.picHead + item.get_save_pic2;
            }
            if (item.get_save_pic2&&item.get_save_pic2.indexOf('http') == -1) {
                item.get_save_pic2 = config.appsetting.picHead + item.get_save_pic2;
            } 
            if (item.get_save_pic3&&item.get_save_pic3.indexOf('http') == -1) {
                item.get_save_pic3 = config.appsetting.picHead + item.get_save_pic3;
            } 
            if (item.get_save_pic4&&item.get_save_pic4.indexOf('http') == -1) {
                item.get_save_pic4 = config.appsetting.picHead + item.get_save_pic4;
            } 
            if (item.get_save_pic5&&item.get_save_pic5.indexOf('http') == -1) {
                item.get_save_pic5 = config.appsetting.picHead + item.get_save_pic5;
            } 
            if (item.get_save_pic6&&item.get_save_pic6.indexOf('http') == -1) {
                item.get_save_pic6 = config.appsetting.picHead + item.get_save_pic6;
            } 

            if (item.other_pic1&&item.other_pic1.indexOf('http') == -1) {
                item.other_pic1 = config.appsetting.picHead + item.other_pic1;
            } 
            if (item.other_pic2&&item.other_pic2.indexOf('http') == -1) {
                item.other_pic2 = config.appsetting.picHead + item.other_pic2;
            } 
            if (item.other_pic3&&item.other_pic3.indexOf('http') == -1) {
                item.other_pic3 = config.appsetting.picHead + item.other_pic3;
            } 
            if (item.other_pic4&&item.other_pic4.indexOf('http') == -1) {
                item.other_pic4 = config.appsetting.picHead + item.other_pic4;
            } 
            if (item.other_pic5&&item.other_pic5.indexOf('http') == -1) {
                item.other_pic5 = config.appsetting.picHead + item.other_pic5;
            } 
            if (item.other_pic6&&item.other_pic6.indexOf('http') == -1) {
                item.other_pic6 = config.appsetting.picHead + item.other_pic6;
            } 
            
            
        })
        let queryHb = `select name from home_base where id = '${pid}'`;
        let resulthb = yield this._daoModel.query(queryHb);

        r   = result.rows
        let hbName = resulthb.rows[0].name;
        return {
            code: 1,
            successed: true,
            rows: r,
            hbName:hbName
        }
    }

    // // 获取公司历史审核
    // * getAllHxByHbId(req, res) {
    //     let r = {};
    //     let hbId = req.params.hbId;
    //     let sql = `SELECT * FROM home_base_hx WHERE pid = ` + hbId + ` order by up`;
    //     let result = yield this._daoModel.query(sql);
    //     r   = result.rows

    //     return {
    //         code: 1,
    //         successed: true,
    //         rows: r
    //     }
    // }


    * getInsertHx(req, res) {
        let r = {};
        let pid = req.body.pid;
        let uid = req.body.uid;

        // 该公司可能有待办的 
        let queryHxByPid = `select * from home_base_hx where pid = '${pid}'`;
        let queryHx = yield this._daoModel.query(queryHxByPid);
        if(queryHx.rows.length != 0){
            let hxSql = `SELECT * FROM home_base_hx WHERE pid = '${pid}' order by sort desc `
            let queryHx = yield this._daoModel.query(hxSql);
            //如果有待办" 请先完成待办
            if (queryHx.rows[0].ys == 0) {
                r.insertId = queryHx.rows[0].id
                return {
                    code: 1,
                    successed: true,
                    rows: r,
                    msg:"请先完成待办"
                }
            }
        }

        // 先拿到总行数i 并且+1
        let i = queryHx.rows.length + 1
        // let note='第'+i+'次开始检查'
        // let insertHxSql = `INSERT INTO home_base_hx(note, pid, sort) VALUES ('${note}', '${pid}', '${i}')`;
        let today = date.format(new Date(), 'YYYY-MM-DD HH:mm:ss'); //当前时间
        
        let insertHxSql = `INSERT INTO home_base_hx(create_time, pid, sort, uid) VALUES ('${today}', '${pid}', '${i}', '${uid}')`
        let result = yield this._daoModel.query(insertHxSql);
        r   = result.rows

        //修改home_base 的checktime  和hxid 
        let incSql = 'UPDATE home_base SET hxid='+r.insertId+',check_time = '+i+' WHERE id  = ' + pid;
        yield this._daoModel.query(incSql);


        return {
            code: 1,
            successed: true,
            rows: r
        }
    }

    * getInsertHbAndHx(req, res) {
    
        let r = {};
        // 插入新公司记录
        let name = req.body.name;
        let fr = req.body.fr;
        let idCard = req.body.id_card;
        let uid = req.body.uid;
        let pics = req.body.pics;
        let phone = req.body.phone;
        let sf = req.body.sf;
        let sq = req.body.sq;
        let qy = req.body.qy;
        let jd = req.body.jd;
        let address = req.body.address;
        let cslx = req.body.cslx;
        let glyphone = req.body.glyphone;
        let glyname = req.body.glyname;
	   let here =yield this.checkuser(uid);

        let resultHB = yield this._daoModel.query(" select *  from home_base where name = '"+name+"'");
        if(resultHB.rows.length>0){

            let updateHbSql=`update home_base set name='${name}' ,  cslx='${cslx}' , glyname='${glyname}' , fr='${fr}' ,id_card='${idCard}' , uid='${uid}' ,pics='${pics}' , phone='${phone}', glyphone='${glyphone}' ,sf='${sf}' , sq='${sq}' ,qy='${qy}' , jd='${jd}', address='${address}' where id='${resultHB.rows[0].id}'  `
            yield this._daoModel.query(updateHbSql);
            return {
                code: 0,
                here: 0,
                successed: true,
                msg: "公司已保存" 
            }
        }

        let sql = `INSERT INTO home_base(name, cslx, glyname, fr, id_card, uid, kfs_id, check_time, pics, phone, glyphone, sf, sq, qy, jd, address, xszt) VALUES ('${name}', '${cslx}', '${glyname}', '${fr}', '${idCard}', '${uid}', '${uid}', '0', '${pics}', '${phone}','${glyphone}', '${sf}', '${sq}', '${qy}', '${jd}', '${address}', '0')`;
        let newHb = yield this._daoModel.query(sql);

        // 新公司记录的id
        let hbId = newHb.rows.insertId;
        let hxSql = `SELECT * FROM home_base_hx WHERE pid = '${hbId}' `
        let queryHx = yield this._daoModel.query(hxSql);

        // 先拿到总行数i 并且+1
        let i = queryHx.rows.length + 1
        let today = date.format(new Date(), 'YYYY-MM-DD HH:mm:ss'); //当前时间

        let note='第'+i+'次开始检查'
        let insertHxSql = `INSERT INTO home_base_hx(create_time, pid, sort, uid) VALUES ('${today}', '${hbId}', '${i}', '${uid}')`;        
        let result = yield this._daoModel.query(insertHxSql);
        let hxId = result.rows.insertId;

        let incSql = 'UPDATE home_base SET check_time = '+i+', hxid='+hxId+' WHERE id  = ' + hbId;
        yield this._daoModel.query(incSql);


        return {
            code: 1,
            successed: true,
            here: here,
            hbId: hbId,
            hxId: hxId
        }
    }

    * getAllPic(req, res) {
        let r = {};
        let pid = req.params.pid||1;
        let sql = `SELECT  a.name , b.* FROM home_base a inner join  home_base_hx b on a.id=b.pid where b.pid=`+ pid +' order by sort ' ;
        let result = yield this._daoModel.query(sql);
        result.rows.map((item, index) => {
            if (item.get_live_pic1.indexOf('http') == -1) {
                item.get_live_pic1 = config.appsetting.picHead + item.get_live_pic1;
            } 
            if (item.get_live_pic2.indexOf('http') == -1) {
                item.get_live_pic2 = config.appsetting.picHead + item.get_live_pic2;
            } 
            
        })
        r   = result.rows
        return {
            code: 1,
            successed: true,
            rows: r
        }
    }


    * getAllPicByhHxid(req, res) {
        let r = {};
        let hxid = req.params.hxid;
        let sql = `SELECT  a.name,a.glyname,a.glyphone,a.sq,a.qy,a.jd,a.address,b.* FROM home_base a inner join  home_base_hx b on a.id=b.pid where b.id=`+ hxid +' order by sort ' ;
        let result = yield this._daoModel.query(sql);
        // result.rows.map((item, index) => {
        //     if (item.get_live_pic1.indexOf('http') == -1) {
        //         item.get_live_pic1 = config.appsetting.picHead + item.get_live_pic1;
        //     } 
        //     if (item.get_live_pic2.indexOf('http') == -1) {
        //         item.get_live_pic2 = config.appsetting.picHead + item.get_live_pic2;
        //     } 
            
        // })
        r   = result.rows
        return {
            code: 1,
            successed: true,
            rows: r
        }
    }

    * saveShyj(req, res) {
        let r = {};
        let id = req.body.id;
        let sh_note = req.body.sh_note;
        let zg_time = req.body.zg_time;
        let create_time = req.body.date;


        var a1 = Date.parse(new Date(zg_time));  //整改时间
        var a2 = Date.parse(new Date());  //当前时间
        let zgsj = parseInt((a1-a2))
        if(zgsj<2) 
        {
            return {
                code: 0,
                successed: false,
                msg: "整改期限需在排查时间之后"
            }
        }




        // 保存审核意见和整改时间
        let sql = `update home_base_hx set sh_note = '${sh_note}', zg_time = '${zg_time}',  create_time = '${create_time}',  del = 0 where id = '${id}'`  ;
        let result = yield this._daoModel.query(sql);

        // 拿hx的updatetime作为hb更新审核时间 同时修改整改时间 以及颜色和记录违规项目
        let hxsql = `select * from home_base_hx where id= '${id}'`;
        let hxdetail = yield this._daoModel.query(hxsql);
        let hxupdate_time = hxdetail.rows[0].update_time;
        let hxpid = hxdetail.rows[0].pid;
        let hxys = hxdetail.rows[0].ys;
        let hxnote = hxdetail.rows[0].note;
        let hbsql = `update home_base set hxid = 0, sh_time = '${hxupdate_time}', zg_time = '${zg_time}', ys = '${hxys}', note = '${hxnote}' where id = '${hxpid}' `;
        yield this._daoModel.query(hbsql);
        r   = result.rows;
        r.sh_note = sh_note;
        r.zg_time = req.body.zg_time;
        return {
            code: 1,
            successed: true,
            rows: r
        }
    }


    * save11(req, res) {
        let r = {};
        let id = req.body.id;
        let sh_note = req.body.sh_note;
        let zg_time = req.body.zg_time;

        var a1 = Date.parse(new Date(zg_time));  //整改时间
        var a2 = Date.parse(new Date());  //当前时间
        let zgsj = parseInt((a1-a2))
        if(zgsj<2) 
        {
            return {
                code: 0,
                successed: false,
                msg: "整改期限需在排查时间之后"
            }
        }

        // 保存审核意见和整改时间
        
        // 设置更新时间
        let today = date.format(new Date(), 'YYYY-MM-DD HH:mm:ss'); //当前时间
        let sql = `update home_base_hx set sh_note = '${sh_note}', zg_time = '${zg_time}', update_time = '${today}', del = 0 where id = '${id}'`  ;
        let result = yield this._daoModel.query(sql);

        // 拿hx的updatetime作为hb更新审核时间 同时修改整改时间 
        let hxsql = `select update_time, pid from home_base_hx where id= '${id}'`;
        let hxdetail = yield this._daoModel.query(hxsql);
        let hxupdate_time = hxdetail.rows[0].update_time;
        let pid = hxdetail.rows[0].pid;
        let hbsql = `update home_base set sh_time = '${hxupdate_time}', zg_time = '${zg_time}' where id = '${pid}' `;
        yield this._daoModel.query(hbsql);
        r   = result.rows;
        r.sh_note = sh_note;
        r.zg_time = req.body.zg_time;
        return {
            code: 1,
            successed: true,
            rows: r
        }
    }

    * checkuser(uid) {
        let here=1;  
        let user  = yield this._daoModel.query(`SELECT * FROM home_kfs where del=0 and id= ` + uid); //查询没删除的    
        if(user.rows.length==0) here=0 ; 
        return  here;
    }

    * getSSQByPId(req, res) {
    	   let here =1;
        let r = {};
        let parend_id = req.params.pid;
        let districtSql = `SELECT * FROM bas_district WHERE parent_id = '${parend_id}' `
        let queryDistructSql = yield this._daoModel.query(districtSql);
        
        r   = queryDistructSql.rows

        return {
            code: 1,
            successed: true,
            here: here,
            rows: r
        }
    }

}
exports = module.exports = Indexcontroller;